When I find errors in my validateform() script I want to stay on the form and let the user fix the errors. My code is not working – it goes to the next webpage nomatter what? How do you get it to stay. I believe if the onclick validateform() is false it should stay. I must be doing something wrong.
Newbie – TIA
function ValidateForm() {
var flag = true
var Tester = document.forms.guestbook
if (Tester.Gname.value == “”) {
alert(“Please enter a name.”)
flag = false
}
if (checkemail() == false) {
alert(“Please input a valid email address.”)
flag = false
}
if (Tester.security_code.value != Tester.code.value) {
alert(“Please enter a correct security code.”)
flag = false
}
alert(flag)
if (flag == true) {
document.forms.guestbook.submit()
}
}
<input type=”submit” name=”submit” value=”Submit” onClick=”ValidateForm()”/>