-1

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

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);
    }
}

Edited by Nick Evan: Fixed formatting

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Graphix
0

. . .
else if ((addteam.teamamanger.value.length < 3) || (addteam.teammanager.value.length > 20))
. . .

Misspelling "manager" probably doesn't help.

0

>> Always put code in code tags:

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);
}
}

The errors in your script:

>> Line 4, 11, 15, 21 - You forgot to add the document. add the beginning. Use: document.addteam.teamname or document.addteam.teammanager >> Line 7,8,17,18 - You forgot to end the line with a ;

>> Line 13, 23,27 - You can just use: return true; or return false; >> Line 15 - teamamanger needs to be teammanager like DavidB mentioned

~G

Edited by Graphix: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.