Skip to content

Instantly share code, notes, and snippets.

@imarkdesigns
Created October 17, 2012 01:48
Show Gist options
  • Select an option

  • Save imarkdesigns/3903272 to your computer and use it in GitHub Desktop.

Select an option

Save imarkdesigns/3903272 to your computer and use it in GitHub Desktop.
Disabled Submit Button with jQuery Script
<form>
<input type="checkbox" name="agree" id="agree" value="1">
<button type="submit" class="btn">Accept Terms & Conditions</button>
</form>
<script>
$(function(){
$('.btn').attr('disabled', 'disabled');
$('#agree').click(function(){
if($(this).is(':checked')) {
$('.btn').removeAttr('disabled').addClass('btn-primary');
} else {
$('.btn').attr('disabled', 'disabled').removeClass('btn-primary');
}
});
});
</script>
@imarkdesigns

Copy link
Copy Markdown
Author

Creating jQuery function that disable submit button when user didn't check the check-box field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment