diff --git a/FormularioInicial.php b/FormularioInicial.php
index c53ae8a..23d5dfa 100644
--- a/FormularioInicial.php
+++ b/FormularioInicial.php
@@ -231,15 +231,34 @@ while ($row = $result->fetch_assoc()) {
}
function mostrarInputOtro(tipo) {
- const selectElement = document.getElementById(tipo);
- const inputOtroElement = document.getElementById(tipo + '_otro');
+ const select = document.getElementById(tipo);
+ const inputOtro = document.getElementById(tipo + '_otro');
- if (selectElement.value === 'otro') {
- inputOtroElement.classList.remove('d-none');
- inputOtroElement.setAttribute('required', 'required');
+ if (select.value === 'otro') {
+ inputOtro.classList.remove('d-none');
+ inputOtro.required = true;
} else {
- inputOtroElement.classList.add('d-none');
- inputOtroElement.removeAttribute('required');
+ inputOtro.classList.add('d-none');
+ inputOtro.value = '';
+ inputOtro.required = false;
+ }
+
+ // Si cambias proveedor, resetea examen y certificación
+ if (tipo === 'empresa') {
+ // Oculta y limpia examen_otro y certificacion_otro
+ document.getElementById('examen_otro').classList.add('d-none');
+ document.getElementById('examen_otro').value = '';
+ document.getElementById('examen_otro').required = false;
+
+ document.getElementById('certificacion_otro').classList.add('d-none');
+ document.getElementById('certificacion_otro').value = '';
+ document.getElementById('certificacion_otro').required = false;
+ }
+ // Si cambias examen, resetea certificación
+ if (tipo === 'examen') {
+ document.getElementById('certificacion_otro').classList.add('d-none');
+ document.getElementById('certificacion_otro').value = '';
+ document.getElementById('certificacion_otro').required = false;
}
}
@@ -258,17 +277,22 @@ while ($row = $result->fetch_assoc()) {
examenSelect.appendChild(option);
}
}
- const optionOtro = document.createElement("option");
- optionOtro.value = "otro";
- optionOtro.textContent = "Otro";
- examenSelect.appendChild(optionOtro);
+ if (!Array.from(examenSelect.options).some(opt => opt.value === "otro")) {
+ const optionOtro = document.createElement("option");
+ optionOtro.value = "otro";
+ optionOtro.textContent = "Otro";
+ examenSelect.appendChild(optionOtro);
+ }
+
// Reinicia certificaciones
- certificacionSelect.innerHTML = '';
- const optionCertOtro = document.createElement("option");
- optionCertOtro.value = "otro";
- optionCertOtro.textContent = "Otro";
- certificacionSelect.appendChild(optionCertOtro);
+ certificacionSelect.innerHTML = '';
+ if (!Array.from(certificacionSelect.options).some(opt => opt.value === "otro")) {
+ const optionCertOtro = document.createElement("option");
+ optionCertOtro.value = "otro";
+ optionCertOtro.textContent = "Otro";
+ certificacionSelect.appendChild(optionCertOtro);
+ }
}
function actualizarCertificaciones() {
@@ -286,11 +310,13 @@ while ($row = $result->fetch_assoc()) {
certificacionSelect.appendChild(option);
});
}
- // Siempre agrega la opción "Otro"
- const optionOtro = document.createElement("option");
- optionOtro.value = "otro";
- optionOtro.textContent = "Otro";
- certificacionSelect.appendChild(optionOtro);
+ // Solo agrega la opción "Otro" si no existe ya
+ if (![...certificacionSelect.options].some(opt => opt.value === "otro")) {
+ const optionOtro = document.createElement("option");
+ optionOtro.value = "otro";
+ optionOtro.textContent = "Otro";
+ certificacionSelect.appendChild(optionOtro);
+ }
}
document.getElementById("registroForm").addEventListener("submit", function(e) {
@@ -447,5 +473,4 @@ document.addEventListener('DOMContentLoaded', function() {