javascript validation question

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

javascript validation question

Post 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>
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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;
Post Reply