如何重置由php设置检查值的复选框? [英] How do I reset a checkbox thats checked value is set by php?

查看:96
本文介绍了如何重置由php设置检查值的复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

0下来投票最爱





我有一个带有大量复选框的网页表格。如果表单填写不正确,则不会重置任何复选框(作为反挫折功能)。



问题是,重置按钮不起作用取消选中所有方框。我如何解决这个问题?



document.getElementById(form)。如果事先已提交表单,则reset()不起作用。



示例代码如下:





0 down vote favorite


I have a web form with a bazillion check boxes. If the form is filled out incorrectly, none of the check boxes are reset (as an anti-frustration feature).

Problem is, the reset button doesn't work to uncheck all the boxes. How do I fix this?

document.getElementById("form").reset() doesn't work if the form has been submitted beforehand.

Sample code below:


<body>

<script>
function resetData() {
    document.getElementById("deleteContactFlag").checked=false;
    document.getElementById("userAdministrationFlag").checked=false;
}
</script>

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" id="form">
    <input type="checkbox" name="deleteContactFlag" id="deleteContactFlag" <?php if (isset($_POST["deleteContactFlag"])) echo 'checked="checked"'; ?>/> Delete Contacts
    <input name="userAdministrationFlag" type="checkbox" id="userAdministrationFlag" <?php if (isset($_POST["userAdministrationFlag"])) echo 'checked="checked"'; ?>/> User Administration

    <input type="submit" name="submit" id="submit" value="Submit">
    <button type="button" onClick="resetData()">Reset</button>
</form>





< / body>

[已删除链接]



</body>
[link removed]

推荐答案

_SERVER [ PHP_SELF]); > method =postid =form>
< 输入 < span class =code-attribute> type = 复选框 名称 = deleteContactFlag id = deleteContactFlag <?php 如果 (isset(
_SERVER["PHP_SELF"]); ?>" method="post" id="form"> <input type="checkbox" name="deleteContactFlag" id="deleteContactFlag" <?php if (isset(


_POST [deleteContactFlag])) echo '已检查 = 已检查 '; > />删除联系人
< 输入 名称 = userAdministrationFlag type = 复选框 id = userAdministrationFlag <?php 如果 (isset(
_POST["deleteContactFlag"])) echo 'checked="checked"'; ?>/> Delete Contacts <input name="userAdministrationFlag" type="checkbox" id="userAdministrationFlag" <?php if (isset(


_POST [userAdministrationFlag])) echo '已检查 = 已选中 '; > />用户管理

< 输入 type = submit name = 提交 id = 提交 value = 提交 >
< 按钮 type = 按钮 onClick = resetData() > 重置< ; / button >
< / form >
_POST["userAdministrationFlag"])) echo 'checked="checked"'; ?>/> User Administration <input type="submit" name="submit" id="submit" value="Submit"> <button type="button" onClick="resetData()">Reset</button> </form>





< / body>

[已删除链接]



</body>
[link removed]


这篇关于如何重置由php设置检查值的复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆