Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script Help 2

Status
Not open for further replies.

techninut

Technical User
Nov 28, 2001
92
US
I have written a very basic validation script, but can not seem to get it to work. I have pasted the script below. Does anyone know what I am missing here?

<HTML>
<HEAD>
<TITLE>TEST FORM</TITLE>
<SCRIPT LANGUAGE=&quot;JAVASCRIPT&quot;>

function goodForm()
{
IF (FORM1.NAME.VALUE ==&quot;&quot;)
{
ALERT(&quot;Please enter your name&quot;);
FORM1.NAME.FOCUS();
RETURN(FALSE);
}
RETURN(TRUE);
}

</SCRIPT>

<BODY>
<FORM NAME=&quot;FORM1&quot;>
Name
<INPUT TYPE=&quot;TEXT&quot; NAME=&quot;NAME&quot;></INPUT>
<INPUT TYPE=&quot;SUBMIT&quot; VALUE=&quot;SUBMIT&quot; ONSUBMIT=&quot;goodForm()&quot;>
</FORM>
</BODY>
</HTML>




- David
 
function goodForm()
{
IF (document.FORM1.NAME.value == &quot;&quot;)
{
alert(&quot;Please enter your name&quot;);
document.FORM1.NAME.focus();
return false;
}
return true;
}

Remember that Javascript is case sensitive.
 
Ok, I fixed the case issue, however I still have problems with half of this script. I am not getting any error codes which makes it harder to trouble shoot.

Here is the script :

<HTML>
<HEAD>
<TITLE>TEST FORM</TITLE>
<SCRIPT LANGUAGE=&quot;JAVASCRIPT&quot;>

function goodForm(form1)
{
if (form1.name.value ==&quot;&quot;)
{
alert(&quot;Please enter your name&quot;);
form1.name.focus();
return false;
}
if (form1.name.length < 5)
{
alert(&quot;Please enter 5&quot;)
form1.name.focus();
return false;
}

return true;
}

</SCRIPT>

<BODY>
<FORM NAME=&quot;form1&quot; onsubmit=&quot;return goodForm(this)&quot;>
Name
<input type=&quot;text&quot; name=&quot;name&quot;></input>
<input type=&quot;submit&quot; value=&quot;submit&quot;>
</FORM>
</BODY>
</HTML>


The first half works, meaning I receive the alert if the box is blank, however the second half does not work. If I put only 2 characters in the input field I don't get any errors, although I should receive an error if it is anything less than 5 characters. I'm sure I am missing something here, I just do not know what.

- David
 
DSergile,
I changed the field name from name (a javascript property) to name1, and added value to the equation. See the bolding.

function goodForm(form1)
{
if (form1.name1.value ==&quot;&quot;){
alert(&quot;Please enter your name&quot;);
form1.name1.focus();
return false;
}
if (form1.name1.value.length < 5){
alert(&quot;Please enter 5&quot;);
form1.name1.focus();
return false;
}
return true;
}
 
That was it ! Thanks to both of you for all your help. I've been trying to figure that out all week.

Thanks again !!!

- David
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top