View Single Post
Old 17-05-2011, 10:51 AM   #1
wackypanda
Abandonia nerd

 
Join Date: Jan 2011
Location: ,
Posts: 51
Default Javascript form validation

The noob has returned.

Generally, if I want to do form validation I use the following format:

Code:
function validateForm(myForm)
{
if (failure conditions)
  {
  show error message;
  return false;
  }
return true;
}

<form onsubmit="return validateForm(this);"></form>
However, someone once told me it should be done like this:

Code:
function validateForm(myForm)
{
if (failure conditions)
  {
  show error message;
  }
myForm.submit();
}

<form onsubmit="validateForm(this); return false;"></form>
I don't quite get the logic behind the second one. It looks like it forces the user to turn on Javascript to submit the form. That gives me bad vibes.

What are your thoughts?
wackypanda is offline                         Send a private message to wackypanda
Reply With Quote