Jump to content

Form Validation Problem


gilbertsavier

Recommended Posts

Hi,

I am trying to validate a form, and am getting the error messages as needed, but it submits the form anyway.

 

Here is the Java:

 

function validate (form){

 

var returnValue = true;

 

var email = CSLavRequestForm.email.value;

var phone = CSLavRequestForm.phoneNumber.value;

var groupName = CSLavRequestForm.workshopName.value;

 

if (email.length < 6){

returnValue = false;

alert("Please Enter Valid email");

CSLavRequestForm.email.focus();

}

if (phone.length < 10){

returnValue = false;

alert("Please Enter Valid Phone Number");

CSLavRequestForm.phone.focus();

}

if (groupName.length < 3){

returnValue = false;

alert("Please Enter Valid Workshop/Region");

CSLavRequestForm.groupName.focus();

}

 

return returnValue;

}

 

and the form line in the html:

 

 

 

I am stuck! Benn working on this for way too long

 

Thanks & Regards,

Lokananth

Link to comment
Share on other sites

The focus() function after the alerts were sending the form. Removed them and made some changes, and it works

 

function validate(form){
   var returnValue = true;

   var email = form.email.value;
   var phone = form.phoneNumber.value;
   var groupName = form.workshopName.value;

   if (email.length < 6){
       returnValue = false;
       alert("Please Enter Valid email");
   }
   if (phone.length < 10){
       returnValue = false;
       alert("Please Enter Valid Phone Number");
   }
   if (groupName.length < 3){
       returnValue = false;
       alert("Please Enter Valid Workshop/Region");
   }

   return returnValue;
}

 

If anyone's got an explanation why the focus() method sends a form, then please shed some light :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...