我已经为我的 HTML 编写了一个验证器,尽管我不确定我哪里出错了。
我在下面要做的是确定“名字”框中是否有任何文本。代码中有底层的 css,但我相信我的问题是围绕我的 onsubmit 和 validate 函数,因为一旦我单击提交按钮,javascript 中似乎没有任何东西在运行。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>NewPatientForm</title>
<link rel="stylesheet" type="text/css" href="NewPatient.css">
<script>
function validate() {
var invalid = false;
if(!document.Firstname.value.length) {
invalid = true;
}
if(invalid) {
document.getElementById("form-error").style.display = "inline-block";
return false; //to make the text appear
}
return true;
}
</script>
</head>
<body>
<form id="NewPatientForm" method="post" action="#" onsubmit="return validate();">
<div class="form-element">
<p id="form-error">All fields are required</p>
</div>
<div>
<label for="Firstname">First Name
<input type="text" name="Firstname" placeholder="First Name" id="Firstname">
</label>
</div>
<div>
<input type="submit" name="submit-button" value="Submit">
</div>
</form>
</body>
</html>
www说
杨魅力
墨色风雨
随时随地看视频慕课网APP
相关分类