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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form error - WHY WHY WHY???

Status
Not open for further replies.

wuzzle

Programmer
Dec 20, 2000
75
0
0
CA
Ok - I've got one function for reminding them to enter a company name and one reminding them to enter a password.

Here is the javascript:

function formValidation(CompanyName)
{
with (CompanyName)
{
if (emptyValidation(CompanyName, "Please enter a Company Name.") == false)
{
CompanyName.focus();
return false;
}
}
}

function formValidation(PasswordForm)
{
with (PasswordForm)
{
if (emptyValidation(txtPassword, "Please enter a password.") == false)
{
txtPassword.focus();
return false;
}
if (emptyValidation(ConfirmPassword, "Please enter a confirmation password.") == false)
{
ConfirmPassword.focus();
return false;
}

}
}


Here is the input area for the company name:

<form id=form3 name=CompanyName onSubmit=&quot;return(formValidation(CompanyName))&quot;>
<tr>
<td>
<font face=arial,tahoma size=2 color=#000000>
Company Name:&nbsp;
</td>
<td>
<input type=text size=20 maxlength=255 name=CompanyName>
</td>
</tr>
<tr>
<td colspan=2 align=right>
<input type=submit value='Apply Change'><br>
</td>
</tr>
</form>


and here is the input area for their password:

<form id=form1 name=PasswordForm onSubmit=&quot;return(formValidation(PasswordForm))&quot;>
<tr>
<td>
<font face=arial,tahoma size=2 color=#000000>
Password:&nbsp;
</td>
<td>
<input type=text size=12 maxlength=255 name=txtPassword>
</td>
</tr>
<tr>
<td>
<font face=arial,tahoma size=2 color=#000000>
Confirm Password:&nbsp;
</td>
<td>
<input type=text size=12 maxlength=255 name=ConfirmPassword>
</td>
</tr>
<tr>
<td colspan=2 align=right>
<input type=submit value='Apply Change' id=submit1 name=submit1><br>
</td>
</tr>
</form>

Now why, when I click &quot;Apply Change&quot; under the Company Name text area, would it say &quot;Error: 'txtPassword' is undefined&quot;?
 
because it's not defined or passed any value. It's not reading txtPassword os the value from your text, it's reading it as a variable.

Try this instead: document.txtPassword.value &quot;The surest sign that intelligent life exists elsewhere in the universe is that it has never tried to contact us&quot;
Bill Watterson, Calvin & Hobbes
 
So which line should I be replacing with document.txtPassword.value?
 
any reference you make to txtPassword in your script. &quot;The surest sign that intelligent life exists elsewhere in the universe is that it has never tried to contact us&quot;
Bill Watterson, Calvin & Hobbes
 
I tried, and when I click the button it says &quot;document.txtPassword.value is not an object

function formValidation(PasswordForm)
{
//txtPassword=document.PasswordForm.txtPassword;

with (PasswordForm)
{
if (emptyValidation(document.txtPassword.value, &quot;Please enter a password.&quot;) == false)
{
document.txtPassword.value.focus();
return false;
}
if (document.txtPassword.value.length < 6)
{
alert('Your password must be at least 6 characters long.')
}
if (emptyValidation(ConfirmPassword, &quot;Please enter a confirmation password.&quot;) == false)
{
ConfirmPassword.focus();
return false;
}
}
}
 
Yeah, sorry, I was wrong :p. Stick with what you had. This may be related to your other problem, not sure. &quot;The surest sign that intelligent life exists elsewhere in the universe is that it has never tried to contact us&quot;
Bill Watterson, Calvin & Hobbes
 
I guess I just really don't understand why this javascript function and this form code:

function formValidation(CompanyName)
{
with (CompanyName)
{
if (emptyValidation(CompanyName, &quot;Please enter a Company Name.&quot;) == false)
{
CompanyName.focus();
return false;
}
}
}

and...

<form id=form3 name=CompanyName onSubmit=&quot;return(formValidation(CompanyName))&quot;>
<tr>
<td>
<font face=arial,tahoma size=2 color=#000000>
Company Name:&nbsp;
</td>
<td>
<input type=text size=20 maxlength=255 name=CompanyName>
</td>
</tr>
<tr>
<td colspan=2 align=right>
<input type=submit value='Apply Change'><br>
</td>
</tr>
</form>

should have anything at all to do with the password stuff when you submit the form data. RAAA!
 
First of all, you two functions has the same name &quot;formValidation&quot; you only change the parameter variable
so witch one will it pick ?
Keep one and test on the parameter

Another, you refer &quot;CompanyName&quot;,both the form and input has the same name. ?

Best regards
Helge

 
Tis not gunna work if the Input and Form have the same name.

I actually came to this page, looking for help with my very similar code.

function submitform(thisform)
{
with (thisform)
{
if(emptyValidation(uname,&quot;Insert a name&quot;)==false){uname.focus();}
else {
alert(&quot;Hello &quot;+uname.value+&quot;.&quot;);
}
}
}

..and

<form method=&quot;POST&quot; name=&quot;myform&quot;>
<input type=&quot;text&quot; name=&quot;uname&quot; value=&quot;&quot; size=&quot;140&quot;>
<a href=&quot;javascript:submitform(document.myform)&quot;>Click</a>
</form>

When the hyperlink it clicked, i get a debug message saying &quot;Line:33 Error:Object Expected&quot;
Line33 is the &quot;if(emptyValidation&quot; etc. line
There seems to be no problem with it..I need help
 
oops...ignore my dumbness...i missed a pretty vital bit out...the function for emptyValidation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top