【发布时间】:2009-08-05 19:10:47
【问题描述】:
我正在使用以下内容重置我的表单:
<script type="text/javascript">
window.onload = function () {
document.getElementsByName("email_address")[0].value = "";
document.getElementsByName("remove")[0].value = "off";
}
</script>
问题是复选框“删除”似乎在服务器端脚本可以运行之前被重置。因此,实际上用户在复选框上选择的任何内容都会被覆盖并设置为关闭,然后才能运行 php 脚本。然而,输入框“email_address”很好......
测试...
//this is already set to OFF by the time we get here....even if the user may have ticked the checkbox to ON
echo $HTTP_GET_VARS['remove'];
//this is fine, the email_address input is read and not reset...
echo $HTTP_GET_VARS['email_address'];
谁能解释一下? 我显然希望在我的服务器端脚本完成处理后重置表单,但由于某种原因它提前重置了复选框,但输入框还可以......
谢谢!
【问题讨论】:
-
如果您要重置整个表单,只需在表单中添加一个 即可。
-
我认为 chican 是在提交后自动重置,而不是用户启动的。
-
是的,因为表单返回一个消息堆栈,例如“您的电子邮件已成功添加”或“错误,您的电子邮件无效”等,我将这些错误堆栈与表单输出在同一页面上,因此在生成堆栈消息后,我希望清除表单
标签: php javascript