所以我一直在尝试做客户端表单验证。我试图验证名字,然后将其余的工作。我假设Javascript应该检查每个“onkeyup”的字段,并显示我的消息,如果该字段中没有字符,则需要“First Name Required”。我将在下面留下我的表单信息,然后是我以后使用的验证代码。我正在运行将'index.php'链接到'validation.js'的脚本。该脚本位于“”标记旁边的index.php中。客户端表单验证。
感谢您的任何帮助,我真的很感激它。
<form method="POST" name="signup" action="php/processuserform.php">
<input id="firstname" onsubmit="validateFirstName()" placeholder="First Name"
type="text" /><label id="firstnameprompt"></label>
<br><br>
<input id="last_name" onkeyup="validateLastName()" placeholder="Last Name"
type="text" /><label id="last_nameprompt"></label>
<br><br>
<input id="email" onkeyup="validateEmail()" placeholder="Email" type="text" /><label
id="emailprompt"></label>
<br /><br />
<input id="password" onkeyup="validatePassword()" placeholder="Create Password"
type="password" /><label id="passwordprompt"></label>
<br /><br />
<strong>Male</strong><input id="male" value="male" type="radio" /><label
id="maleprompt"></label>
<strong>Female</strong><input id="female" value="female" type="radio" /><label
id="femaleprompt"></label>
<br /><br />
<label for="submit">"I Agree To <a href="#">Terms And Conditions"</a></label> <input
id="submit" value="Submit" type="submit" name="submit"/><br /><br />
======================================= ...
现在是我一直在尝试使用的验证。只是试图确保字段不是空的。
function validateFirstName()
{
var name = document.getElementById("firstname").value;
if(name.length == 0)
{
producePrompt("First Name Required", "firstnameprompt", "red");
return false;
}
}
function producePrompt(message, promptlocation, color)
{
document.getElementById(promptLocation).innerHTML = message;
document.getElementById(promptLocation).style.color = color;
}
有什么问题? – yogi
脚本标签位于结束标签的旁边。 – user3066599
它不会显示错误 – user3066599