Tengo un menú desplegable deshabilitado por defecto. Quiero habilitarlo cuando el campo de persona del área de texto no esté vacío.
Cuando se elimina el valor del campo de persona del área de texto, el campo desplegable debe vaciarse y deshabilitarse.
Código actual que no funciona:
$('[id*="DDL"]').prop('disabled', true); $('[id*="User"]').click(function () { if (!$(this).is(":empty")) { $('[id*="DDL"]').prop('disabled', false); } else { $('#DDL').prop('selectedIndex', 0); $('[id*="DDL"]').prop('disabled', true); } });¿Qué estoy haciendo mal aquí?
Digamos que tienes este HTML
<textarea name="hello"></textarea> <!-- Example name = hello --> <select name="DDL" id="DDL" disabled></select> <!-- Dropdown --> En su archivo js, puede capturar si el usuario escribe algo en el área de texto usando keyup , validar si ese área de texto está vacía y luego hacer algo si lo está
jQuery
$(document).on("keyup","[name=hello]", function () { if($("#DDL").val() == ""){ // Check if textarea is empty $("#DDL").prop("disabled", false); // Remove disabled attrib // Do things here } });