I have a dropdown disabled by default. I want to enable it when the the textarea person field is not empty.
When the textarea person field value is removed, the dropdown field should be emptied and disabled.
Current code which is not working:
$('[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);
}
});
What am I doing wrong here?
Let's say you have this HTML
<textarea name="hello"></textarea> <!-- Example name = hello -->
<select name="DDL" id="DDL" disabled></select> <!-- Dropdown -->
In your js file, you can capture if the user types something on the textarea by using keyup, validate if that textarea is empty then do something if it is
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
}
});