I have the following jQuery code to disable a submit button in a form when the values are empty. the code works fine for all entries except for .action_manager
(which is a textarea
generated dynamically in a table)in which by filling only the first row, the button is enabled. I want all the fields to be filled before the submitbutton
is reactivated. Only one instance of action_manager
is enough to get the button enabled ( which is not what I want)
$('document').ready(function(){
var submitButton = $('input[name="store_values"]');
checkValues();
$('select.actuallevel').on('change',function(){
checkValues();
});
$('select.targetlevel').on('change',function(){
checkValues();
});
$('select.quarter_manager').on('change',function(){
checkValues();
});
$('select.year_manager').on('change',function(){
checkValues();
});
$(".action_manager").each(function()
{
$(this).on('change',function(){
checkValues();
});
});
function checkValues(){
submitButton.prop('disabled',$(".actuallevel > option:selected[value=''],.actuallevel:empty").length > 0 ||
$(".targetlevel > option:selected[value=''],.targetlevel:empty").length > 0 ||
$(".quarter_manager > option:selected[value=''],.quarter_manager:empty").length > 0 ||
$(".year_manager > option:selected[value=''],.year_manager:empty").length > 0 ||
!$.trim($(".action_manager").val())
);
//submitButton.prop('disabled',$(".targetlevel > option:selected[value=''],.targetlevel:empty").length > 0);
}
});
The textarea field is the following:
echo "<td><textarea class='action_manager' id='action-".$inf['Competence_ID']."' name='acto-".$inf['Competence_ID']."'>";if (isset($inf['actiontext'])){echo $inf['actiontext'];}echo "</textarea></td>";
echo"<td>";