hi guys, decided to use javascript for validation but once i click submit the error message pops up and then still carrys on to the proccess page. i need it to stop after the error message so the user can type in name again.
this what i got so far
thanx!
<script>
var errormessage = ""
function validate_form()
{
errormessage = "You have the following errors:\n"
Name()
if (errormessage != "You have the following errors:\n")
{
alert(errormessage)
window.document.index.E_Name.focus();
return (false);
}
}
function Name()
{
var name = window.document.index.E_Name.value
if (name == "")
{
errormessage = errormessage + "- Please enter your name\n"
}
}
</script>
javascript validation question
Moderator: General Moderators
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
window.stop() maybe. Or make it so the button you press to submit doesnt submit, but calls the javascript check function and then only if that is complete do you use javascript to send the form:
Code: Select all
somecheck(){
//check the stuff here
if(check){
document.<form name>.submit();
}else{
alert("please fill in the form properly.");
}
}