JQuery / Javascript - submit a form by clicking on a checkmark

I have a page where I show the database of the results form, and there are checkboxes that filter the results. The problem is that I do not want to use the submit button, because I would like to allow the user to only click on the checkboxes to get the desired results. Anyway, using javascript or jquery to submit the form when the checkbox is checked, without the submit button? if you see on trading sites, there are no buttons to send only flags. thanks

<form> <input type="checkbox" name="size" > Size </form> 

here is php

 <?php if (isset($_POST["size"])){ //do something ?> 
+4
source share
2 answers
 <form id="form" method="post" action=""> <input type="checkbox" name="checkbox" class="checkbox"/> </form> <script type="text/javascript"> $(function(){ $('.checkbox').on('change',function(){ $('#form').submit(); }); }); </script> 

OR

 <form id="form" method="post" action=""> <input type="checkbox" onchange="$('#form').submit();" name="checkbox" class="checkbox"/> </form> 
+23
source
 $(input:name=[checkboxname]).change(function(){ $('#form').submit(); }); 

alternately

  $('#checkboxId').click(function(){ $('#formId').submit(); }); 

Of course, additional parameters can be passed using the submit () function for ajax, etc.

+2
source

Source: https://habr.com/ru/post/1496033/


All Articles