prop('disabled', false); is not working
11,200
Solution 1
In your code, this
refers to the DOM.
Change it to
$("#agree").change(function() {
if ($(this).is(':checked')) {
$('#button').prop('disabled', false);
} else {
$('#button').prop('disabled', true);
}
});
Inside the event handler, this
refers to the element that triggered the change event.
or simply:
$("#agree").click(function() {
$('#button').prop('disabled', !$(this).is(':checked'));
});
Solution 2
You can try removing the attribute.
$('#button').removeAttr('disabled')
Author by
Dmytro Petrenko
Updated on September 06, 2022Comments
-
Dmytro Petrenko over 1 year
I want to make a button that will be disable when checkbox is false. But
prop('disabled', false);
isn't working.$(function() { $(this).click(function() { if ($('#аgree').prop(':checked')) { $('#button').prop('disabled', false); } else { $('#button').prop('disabled', true); } }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <p class="text-center">З правилами анкетування ознайомлений(а) і згоден(на) @Html.CheckBox("Agree", false, new { id = "agree" }) </p> <p class="text-center"><input type="button" id="button" disabled="disabled" value="Пройти анкетування" onclick="location.href='@Url.Action("Form")'" /></p>
-
Dmytro Petrenko over 6 years$("#agree").click(function() { $('#button').prop('disabled', !$(this).is(':checked')); }); It`s right. Thank you
-
Kewal Shah almost 5 yearsThanks, I had the same problem as OP but this solution worked like a charm!