Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery / Javascript - submit form when checkbox is clicked [closed]

I have a page where I display results form database and there are checkboxs which filter ther results. The problem is that I don't want to use submit button because I would like to let the user only click on the checkboxes to get the desired results. So is there anyway using javascript or jquery to submit a form when checkbox is checked with no submit button? if you see on shopping sites there are no submit buttons just the checkboxes..Like that. thanks

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

here is the php

<?php if (isset($_POST["size"])){
  //do something
?>
like image 738
user2510039 Avatar asked Aug 08 '13 20:08

user2510039


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>
like image 131
itsme Avatar answered Nov 11 '22 10:11

itsme


$(input:name=[checkboxname]).change(function(){

 $('#form').submit();

});

alternately

 $('#checkboxId').click(function(){

    $('#formId').submit();

  });

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

like image 42
Alex Hill Avatar answered Nov 11 '22 10:11

Alex Hill