Page 1 of 1

javascript validation question

Posted: Thu Jul 08, 2004 12:41 am
by C_Calav
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>

Posted: Thu Jul 08, 2004 6:41 am
by kettle_drum
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()&#123;
   //check the stuff here
   if(check)&#123;
      document.<form name>.submit();
   &#125;else&#123;
      alert("please fill in the form properly.");
   &#125;
&#125;