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: 250

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 set the custom front page in drupal
0 Thirupathi 5 Mon Mar 22, 2010 4:24 am
Thirupathi View latest post
No new posts How to get detailed information about server.
0 AnilKumar 6 Mon Mar 22, 2010 3:42 am
AnilKumar View latest post
No new posts Upload large file using htaccess file in php
0 AnilKumar 14 Fri Mar 19, 2010 7:06 am
AnilKumar View latest post
No new posts subtracting tha dates from present date using php
0 rajkumar 15 Fri Mar 19, 2010 4:58 am
rajkumar View latest post
No new posts How to change Admin theme in drupal
0 Thirupathi 15 Fri Mar 19, 2010 4:48 am
Thirupathi View latest post
No new posts problem with plesk
1 Sanjana 17 Fri Mar 19, 2010 4:41 am
rajkumar View latest post
No new posts Pagination in smarty using php and mysql
0 AnilKumar 17 Fri Mar 19, 2010 4:06 am
AnilKumar View latest post
No new posts highlet source code in php application
0 Sanjana 22 Thu Mar 18, 2010 11:04 am
Sanjana View latest post
No new posts Get the status from twitter using PHP script
1 Thirupathi 38 Tue Mar 16, 2010 4:41 am
Phani Kumar View latest post
No new posts Error: CakephpController could not be found.
0 Mike 20 Tue Mar 16, 2010 4:21 am
Mike 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