I expect to check/uncheck a checkbox and have it enable/disable a submit button. Javascript fires, doesn't show errors, but the submit input just will not toggle more than once.
JS:
$('#readTerms').change(function() {
var buttonsChecked = $('#readTerms:开发者_运维知识库checked');
if (buttonsChecked.length)
{
$('#submitBusiness').removeAttr('disabled');
}
else
{
$('#submitBusiness').attr('disabled', 'disabled');
}
});
HTML:
<input type="checkbox" id="readTerms" name="agree"> <label for="agree">By checking the box you agree to the <a href="/terms" target="_blank">Terms & Conditions</a>.</label>
<input id="submitBusiness" class="btn positive iconCheck right" type="submit" name="create" value="Submit" disabled="disabled" />
Submit button starts disabled. Click the checkbox and it enables, click the checkbox again and nothing. The if/else statement works fine. The code fires, it trips breakpoints in firebug, etc. etc. etc.
What am I doing wrong?
I would try something like this instead:
$('#readTerms').click(function() {
var buttonsChecked = this.checked;
if (buttonsChecked == true){
$('#submitBusiness').removeAttr('disabled');
}else{
$('#submitBusiness').attr('disabled', 'disabled');
}
});
Try something like this:
$('#readTerms').change( function() {
$('#submitBusiness').attr('disabled', !this.checked);
});
Example: http://jsfiddle.net/redler/TETg6/
精彩评论