http://jsfiddle.net/just4upvp/Gt8TY/1/
我是 javascript 的新手,我无法在我的代码中找到错误,validateForm 正在工作,现在它无法正常工作。请帮忙。
<script type="text/javascript">
function validateForm() {
if (document.enrollment.cfname.value == "") {
errcfname.innerHTML = "Please enter firstname";
return false;
}
}
function validate(id,error) {
var value = document.getElementById(id).value;
var err = document.getElementById(error);
if(!value) {
err.innerHTML = "*required";
} else {
err.innerHTML = "*";
}
}
</script>
<form name="enrollment" method="post" action="confirmation.php"
enctype="multipart/form-data" onsubmit="return (validateForm());">
<label for="cfname">First Name:</label>
<input type="text" id="cfname" name="cfname" size="20" maxlength="15"
autofocus="autofocus" required="required"
onblur="validate(this.id,'errcfname')"/>
<span class="error1" id="errcfname">*</span>