I'm trying to make an inline javascript form validation and I have the following java script:
function checkForm() {
subject_code = document.getElementById("subject_code").value;
lectures= document.getElementById("lectures").value;
if (subject_code == "") {
hideAllErrors();
document.getElementById("codeError").style.display = "inline";
document.getElementById("subject_code").select();
document.getElementById("subject_code").focus();
return false;
}
else if (lectures.selectedIndex == "") {
hideAllErrors();
document.getElementById("lectError").style.display = "inline";
lectures.focus;
return false;
}
return true;
}
function hideAllErrors() {
document.getElementById("codeError").style.display = "none"
document.getElementById("lectError").style.display = "none"
}
and I have also this:
<form onsubmit="return checkForm(this);" name="addForm" action="success.jsp" method="post" > <input type="text" name="subject_code" id="subject_code" value="" size=55 maxlength=10/> <div class=error id=codeError>Required: Please enter your Subject Code</div> <select name="lectures" id="lectures"> <option value="" selected="selected"></option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> </select> <div class=error id=lectError>Required: Please select Number of Lectures</div> <input type="submit" value="Save"/>
Now my problem is that when I don't choose from the list box is display me the error for 1 second and immediately the form is submitted and it shouldn't be. The text box error works fine...
Thanks

New Topic/Question
Reply



MultiQuote




|