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
我有一个页面,我显示结果表格数据库,并有复选框,筛选结果。问题是我不想使用提交按钮,因为我想让用户只需单击复选框即可获得所需的结果。因此,当选中复选框而没有提交按钮时,是否仍然使用javascript或jquery提交表单?如果你在购物网站上看到,只有复选框没有提交按钮。就像那样。谢谢
<form>
<input type="checkbox" name="size" > Size
</form>
here is the php
这是php
<?php if (isset($_POST["size"])){
//do something
?>
2 个解决方案
#1
24
<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>
#2
2
$(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.
当然可以使用ajax等的submit()函数传递其他参数。
#1
24
<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>
#2
2
$(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.
当然可以使用ajax等的submit()函数传递其他参数。