Senior & Expert PHP Developers Discussion Forum by Nyros Technologies

HIRE PHP Expert Developers Programmers Coders From India
PHP .Net Ruby on Rails Developers Community, Nyros Technologies, Kakinada
 
Log in  or IF not a member please REGISTER
Username:
Password:   


Keyword
Log in | Profile 

Form Validation Problem

 
Post new topic   Reply to topic    Senior & Expert PHP Developers Discussion Forum by Nyros Technologies Index -> Javascript
View previous topic :: View next topic  
Author Message
gilbertsavier



Joined: 26 Jun 2009
Posts: 17

PostPosted: Tue Jun 30, 2009 9:58 am    Post subject: Form Validation Problem Reply with quote

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;
}
</script>

and the form line in the html:

<form onsubmit="return validate(this);" action="/cgi-sys/formmail.pl" method="post" name="CSLavRequestForm" id="CSLavRequestForm" >


I am stuck! Benn working on this for way too long
_________________
Thanks & regards
Lokananth
By miOOt
Back to top
View user's profile Send private message
venkatadapa



Joined: 12 May 2008
Posts: 307

PostPosted: Wed Jul 01, 2009 4:47 am    Post subject: Reply with quote

Hi gilbertsavier,

You gave "returnValue=true" at starting of the function. Thats why form submited even errors occured. So In first line of the validate function replace 'returnValue=true' with 'returnValue=false'. Make this returnValue true only when after all coditions true.

I Changed your javascript code as below. It will definetely help you.

<script type="text/javascript">
function validate (frm)
{
var email = frm.email.value;

var phone = frm.phoneNumber.value;

var groupName = frm.workshopName.value;

if (email.length < 6)
{
alert("Please Enter Valid email");
frm.email.focus();
return false;
}
else if (phone.length < 10){
alert("Please Enter Valid Phone Number");
frm.phoneNumber.focus();
return false;
}
else if (groupName.length < 3){
alert("Please Enter Valid Workshop/Region");
frm.workshopName.focus();
return false;
}
return true;
}
</script>

All the best, Laughing Laughing
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Senior & Expert PHP Developers Discussion Forum by Nyros Technologies Index -> Javascript
Page 1 of 1

 latest topics 
 Topics   Replies   Author   Views   Last Post 
No new posts how to delete plugins in openinviter
2 aababu 233 Wed Sep 01, 2010 7:27 am
aartylamba View latest post
No new posts ERROR IN PAYPAL PRO
0 tapati 20 Tue Aug 31, 2010 12:35 pm
tapati View latest post
No new posts file_exists always return false
0 orenk 114 Mon Aug 16, 2010 9:49 pm
orenk View latest post
No new posts problem with include fuction
0 bluearrow 117 Mon Aug 16, 2010 1:02 pm
bluearrow View latest post
No new posts Javascript not working in smarty .tpl files
1 samir 107 Mon Aug 16, 2010 5:42 am
venkatadapa View latest post
No new posts Add slashes automatically to all post params
0 samir 111 Mon Aug 16, 2010 5:18 am
samir View latest post
No new posts SMTP server settings when send mails through phpmailer class
0 venkatadapa 96 Mon Aug 16, 2010 4:49 am
venkatadapa View latest post
No new posts Parse the xml string content and display in browser using JS
0 venkatadapa 114 Mon Aug 09, 2010 1:22 pm
venkatadapa View latest post
No new posts Parse the xml file content and display in browser using JS
0 venkatadapa 119 Mon Aug 09, 2010 1:18 pm
venkatadapa View latest post
No new posts hipay
1 hassene003 142 Mon Aug 09, 2010 12:35 pm
aababu View latest post





Hire an expert PHP developer / coder / programmer or development team from India now!!

Other Forums : Ruby on Rails   ::   .Net   |   Free unlimited HTML CSS Joomla Wordpress Drupal templates download

Nyros Technologies   |   Developers Blog   |   Kakinada City Portal   |   About PHP Experts   |   More