一次提交表单,可以产生两个页面,但是,如何避免用户直接按回车键提交呢??
如下代码,一次提交表单,可以产生两个页面
======================================================
<html>
<head>
<title>
一次提交到两个页面
</title>
<script language="Javascript" ranat="client">
<!--
function chk_form() {
if(document.form1.str.value=="")
alert("字符串不能为空。");
else
{
document.form1.action="test.asp";
document.form1.target="_blank";
document.form1.submit();
document.form1.action="test-2.asp";
document.form1.target="_self";
document.form1.submit();
}
}
-->
</script>
</head>
<body>
一次提交到两个页面办法
<hr>
<form method="get" action="" name="form1" TARGET="_SELF">
请输入要查询的字符串: <input type="text" name="str">
<input OnClick="chk_form();" type="button" name="Submit" value="一次提交两个页面办法" >
</form>
</body>
</html>
缺点:
=====================================================
如果是在文本框中直接按回车,那么,
不管文本框是否为空,程序都显示一个新窗口打开
它自身。
=====================================================
如何避免用户直接按回车键提交呢,因为这样数据的有效性得不到检查,我希望通过按钮提交。