Disable Submit Button Until Checkbox is Checked

Here’s an interesting tidbit of code I worked out today for a client website:

$(document).ready(function() {
$('input.button').attr('disabled', true);
$('input.button').attr('value', 'Please accept our terms to submit');
$('.accept input').bind('click', function() {
if ($('.accept input').is(':checked') == true) {
$('input.button').removeAttr('disabled');
$('input.button').attr('value', 'Send Memory');
} else {
$('input.button').attr('disabled', true);
$('input.button').attr('value', 'Please accept our terms to submit');
}
});
});

It’s JQuery for disabling a submit button until a checkbox is checked. In addition, as an added usability feature, the button says “Please accept our terms to submit” so that the user knows why the button isn’t able to be clicked.

In this example “button” is the class of my button and my terms checkbox is wrapped in a span with a class of “accept” (had to work around ASP.NET here at work thank you).

This post will most definitely be useful if I ever look for this functionality again!

This entry was posted in Code Samples and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>