javascript to validate 2 text boxes

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
ryan1987
Forum Newbie
Posts: 16
Joined: Tue Dec 22, 2009 10:45 am

javascript to validate 2 text boxes

Post by ryan1987 »

hi

i want to do validation on two textboxes on my website i am creating. i want to make sure something is entered in each box before the user can proceed. the two textboxes are called teammanager and teamname and are in the form called addteam.

the code i have done only seem to check the first text box and i am new to javascript and cannot workout whats wrong with my code. below is my code help would be much appreciated

Code: Select all

 
function Length_TextField_Validator()
{
// Check the length of the value of the teamname and teammanager
if ((addteam.teamname.value.length < 3) || (addteam.teamname.value.length > 20))
{
// alert box message
mesg = "You have entered " + addteam.teamname.value.length + " character(s)\n"
mesg = mesg + "Valid entries are between 3 and 20 characters for team name.\n"
alert(mesg);
// Place the cursor on the field
addteam.teamname.focus();
// return false to stop user going any further
return (false);
}
else if ((addteam.teamamanger.value.length < 3) || (addteam.teammanager.value.length > 20))
{
mesg = "You have entered " + addteam.teammanager.value.length + " character(s)\n"
mesg = mesg + "Valid entries are between 3 and 20 characters for team manager\n"
alert(mesg);
// Place the cursor on the field
addteam.teammanager.focus();
// return false to stop user going any further
return (false);
}
else {
// If teamname and teammanager is not null continue processing
return (true);
}
} 
 
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Re: javascript to validate 2 text boxes

Post by daedalus__ »

its your if statement
Post Reply