admin管理员组文章数量:1418103
This is my form :
<input type="checkbox" name="dept" value="sales" <?php if(isset($_POST['sales'])) echo "checked='checked'"; ?> onclick="this.form.submit();" /><br />
When i click the checkbox, the page is refreshed with the ?dept=sales in the URL. Just as i want it to be. But the checkbox is unchecked. I want the checkbox to be checked. And when the checkbox is unchecked i want the ?dept=sales to be removed from teh URL.
Thanks.
This is my form :
<input type="checkbox" name="dept" value="sales" <?php if(isset($_POST['sales'])) echo "checked='checked'"; ?> onclick="this.form.submit();" /><br />
When i click the checkbox, the page is refreshed with the ?dept=sales in the URL. Just as i want it to be. But the checkbox is unchecked. I want the checkbox to be checked. And when the checkbox is unchecked i want the ?dept=sales to be removed from teh URL.
Thanks.
Share Improve this question asked Sep 5, 2013 at 10:36 user2742581user2742581 611 silver badge6 bronze badges4 Answers
Reset to default 5Your checkbox's name is dept
, not sales
. The value of your checkbox is sales
. This means that if you want to access the value of your checkbox, you will need to access it via $_POST['dept']
, not $_POST['sales']
. If your form method isn't declared as method="post"
, use $_GET['dept']
instead of $_POST['dept']
.
At first check your check box name, It's dept but you fetch from sales $_POST, another hint is that if your request is shown on the url then it's get not post, If you want to remove parameter from your url add method="post" to your form, At last your code should be like this:
<form action="your action here" method="post">
<input type="checkbox" name="sales" value="sales" <?php if(isset($_POST['sales'])) echo "checked='checked'"; ?> onclick="this.form.submit();" /><br />
</form>
You're checking for an input with the name "sales" change $_POST['sales'] to $_POST['dept'] that'll work :)
Submit the form
only when the checked property true like,
<input type="checkbox" name="dept" value="sales"
<?php if($_REQUEST['dept']=='sales')) echo "checked='checked'"; ?>
onclick="if(this.checked==true) this.form.submit();" /><br />
本文标签: javascriptonclick set php session to keep checkbox checked On uncheck end sessionStack Overflow
版权声明:本文标题:javascript - onclick set php session to keep checkbox checked. On uncheck end session - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745282687a2651517.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论