gpt4 book ai didi

javascript - PHP - 总是需要在表单验证中填写空白

转载 作者:行者123 更新时间:2023-11-30 17:37:47 26 4
gpt4 key购买 nike

我正在尝试实现一些 javascript 表单验证。我正在尝试测试表单中的空白字段并使用警报来警告用户,但这对我不起作用当我提交完整填写的表单时,它一直要求我填写空白。

这是我的代码。希望有人可以追查错误。也许有很多我不明白的错误。非常感谢你

<html>
<head>
</head>

<body>
<br>
<h1 align="center">REGISTRATION

<br>
<font style="font-size:20px">Vendor's Information</font></h1>
<div style="padding-left: 225px">
<br>

<script type="text/javascript">
function form_validate()
{
with(document.form1)
{
if(VENDOR_NAME.value.empty( ))
{
alert("Please fill in the vendor's name");
VENDOR_NAME.focus();
VENDOR_NAME.value="";
return false;
}
if(VENDOR_PHONENUM.value.match( ))
{
alert("Please fill in the vendor's contact number");
VENDOR_PHONENUM.focus();
VENDOR_PHONENUM.value="";
return false;
}
if(VENDOR_PIC.value.match( ))
{
alert("Please fill in the vendor's person in-charge");
VENDOR_PIC.focus();
VENDOR_PIC.value="";
return false;
}
return true;
}

}
</script>

<form name="form1" method="post" action="vendor_registration.php" onSubmit="return form_validate()">
<font face="Verdana">

<table border="0">
<tr style="font-size:15px">
<td>Name</td>
<td>: <input name="VENDOR_NAME" type="text" size="50"><br></td>
</tr>
<tr style="font-size:15px">
<td>Phone No. </td>
<td>: <input name="VENDOR_PHONENUM" type="text" size="50"><br></td>
</tr>
<tr style="font-size:15px">
<td>Person In-Charge</td>
<td>: <input name="VENDOR_PIC" type="text" size="50"><br></td>
</tr>

</table>
</font>
<br/><br/>
<p align="center">
<input type="submit" name="submit" value="Submit" style="font-size: 15px;" >
<input type="reset" name="reset" value="Reset" style="font-size: 15px;">
</p>
</div>
<br>
<br>
</body>
</html>

最佳答案

尝试对空字段检查进行简单验证,

    <script type="text/javascript">
function form_validate()
{
with(document.form1)
{
if(VENDOR_NAME.value == '')
{
alert("Please fill in the vendor's name");
VENDOR_NAME.focus();
return false;
}
if(VENDOR_PHONENUM.value == '')
{
alert("Please fill in the vendor's contact number");
VENDOR_PHONENUM.focus();
return false;
}
if(VENDOR_PIC.value == '')
{
alert("Please fill in the vendor's person in-charge");
VENDOR_PIC.focus();
return false;
}
return true;
}

}
</script>

关于javascript - PHP - 总是需要在表单验证中填写空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21698831/

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