Alex Rivera | Logout

Checkbox value always returns "on"?

Asked 2013-05-17T14:36:33.573
28

I'm trying to return the value of a checkbox to enable and disable a button. Making the checkbox is not a problem, the problem is the check box value always returns on. How should I get a value indicating if the checkbox is checked?

HTML:

<form>
    <input type="checkbox" id="checkbox" /> <label>Do you agree  </label><br />
    <input type="button" value="Continue" id="button" disabled="disabled" />
</form>  

Javascript:

$('#checkbox').change(function(){
    var checkboxValue = $(this).val();
    alert(checkboxValue);
});
Edit
Report

1 Answer

61

Try using prop('checked');

var checkboxValue = $(this).prop('checked');
answered 2013-05-17T14:38:00.287

Your Answer