gpt4 book ai didi

php - Javascript 验证表单提交

转载 作者:行者123 更新时间:2023-11-28 12:40:38 24 4
gpt4 key购买 nike

您好,我想在提交表单之前验证字段值,这是我的代码

<table width="600" border="0" align="left">
<tr>
<script type="text/javascript">
function previewPrint()
{

var RegNumber = document.getElementById('PP_RegNoTextBox').value;
var PassportNo = document.getElementById('PP_PassportNoTextBox').value;
if (RegNumber=="")
{
alert("Please enter your Reg No.!");
document.getElementById('RegNoTextBox').focus();
return false;
}
if (PassportNo=="")
{
alert("Please enter your Passport No.!");
document.getElementById('PassportNoTextBox').focus();
return false;
}
//window.open('regformview.php?RegNumber=RegNumber');
}
</script>
<form name="ppform" onSubmit="return previewPrint();" method="post" action="regformview.php">
<td width="100" align="LEFT" class="font8">&nbsp; </td>
<td width="337" align="LEFT" class="font8"><u>Preview your Application:</u> Please provide requested details.<br>
Reg No.: <input type="text" name="printregno" id="PP_RegNoTextBox" class="input2"> Passport No.: <input type="text" name="printemail" class="input2"><input type="hidden" name="flagging" id="PP_PassportNoTextBox" value="1" class="input2">&nbsp;</td>
<td width="50" align="LEFT" class="font8"><div style="float:left; background-image:url(images/printPreview1.jpg); background-repeat:no-repeat;">
<input type="image" src="images/printPreview1.jpg" name="ppbutton" value="" onMouseOver="this.src='images/printPreview2.jpg'" onMouseOut="this.src='images/printPreview1.jpg'"></div></td>

</form>
</tr>
</table>

问题是,如果警报框为空,但页面在提交后导航到 regformview.php,则会正确显示警报框。如何仅在验证后导航到 regformview.php?

最佳答案

这些未定义:

document.getElementById('RegNoTextBox').focus();
document.getElementById('PassportNoTextBox').focus();

应该是:

document.getElementById('PP_RegNoTextBox').focus();
document.getElementById('PP_PassportNoTextBox').focus();

关于php - Javascript 验证表单提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12615716/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com