i am using a javscript to enable a button based on the changes in the form field in django python using bootstrap.below is the script
JavaScript
x
7
1
$("#employee_name, #employee_name2").on("keyup",function() {
2
$(".btn-action").prop("disabled",false);
3
if( ($("#employee_name").val()) == ($("#employee_name2").val())) {
4
$(".btn-action").prop("disabled",true);
5
}
6
});
7
also the below code in html to initially disable button
JavaScript
1
2
1
<button type="submit" class="btn btn-primary mt-3 btn-action" disabled>Save</button>
2
but the button stays disabled even after changing values in the field.any help would be appreciated
Advertisement
Answer
you need to add the below script
JavaScript
1
8
1
$(document).ready(function(){
2
$("#employee_name,#employee_name2").on("keyup",function(){
3
$(".btn-action2").prop("disabled",false);
4
if(($("#employee_name").val())==($("#employee_name2").val())){
5
$(".btn-action2").prop("disabled",true);
6
}
7
});
8
}); and below in the html
JavaScript
1
2
1
button type="submit" class="btn btn-success mt-3 btn-action2" disabled>Save</button>
2