Submit form when checkbox is checked - tutorial Submit form when checkbox is checked - tutorial ajax ajax

Submit form when checkbox is checked - tutorial


its simple...

<input type="checkbox" onclick="this.form.submit();">


If I understand your question correctly:

You could accomplish this using jQuery and AJAX. In the first example I'm doing it without submitting the whole form, and only submitting the value of the checkbox:

jQuery("#myCheckbox").click(function() {   var $checkbox = jQuery(this);   var checkboxData = "checkboxvalue=" + $checkbox.val();   jQuery.ajax({      url: "http://some.url.here",      type: "POST",      data: checkboxData,      cache: false,      dataType: "json",      success: function(data) {          if(data["success"]) {            //do some other stuff if you have to            //this is based on the assumption that you're sending back            //JSON data that has a success property defined          }      }   });});

Presumably you'd have something on the server-side that handles the post.

If you actually do want to submit a form, you can do the same thing as above, except you'd serialize the form data:

jQuery("#myCheckbox").click(function() {   var formData = jQuery("#formID").serialize();   jQuery.ajax({      url: "http://some.url.here",      type: "POST",      data: formData,      cache: false,      dataType: "json",      success: function(data) {          if(data["success"]) {            //do some other stuff if you have to            //this is based on the assumption that you're sending back            //JSON data that has a success property defined          }      }   });});


<input type="checkbox" onclick="yourForm.submit()">
The above will submit the form when your checkbox is clicked... idk if thats what you want.
So it'll do the default form submit process...