I am using jQuery 1.6 and I would like to submit a form by clicking on a check box button.
That is, I have the following code that submits a form
$jQuery('#search_form').submit(function () {
$jQuery.get(this.action, $jQuery(this).serialize(), null, 'script');
return false;
});
and when I click on a check box which HTML code is
<input type="checkbox" value="true" ... id="check_box_id">
I would like to trigger the form submission.
How can I do that?
You can trigger the
submitevent by simply callingsubmitwith no arguments:Alternatively, you can use the
triggermethod:As it looks like you’re firing an asynchronous request in the submit event handler, rather than using the default form behaviour, I would suggest disabling the checkbox (or removing the event handler) in the
submitevent handler, and then re-enabling it in the success callback of thegetmethod, to prevent the user from submitting repeatedly.