...

View Full Version : Yet another form validation problem



marvinmartian
07-25-2002, 08:45 PM
I am using JavaScript to create a basic form validation routine - essentially just to ensure that ALL fields have been filled in. My problem is that the script works perfectly in Netscape, however, in MSIE, I get the following error right out of the box:

'document.formname.fieldname.value' is not an object.

Can any of you help me resolve this annoying MSIE error. I need this to work on both platforms.

Thanks :-)

mordred
07-25-2002, 09:41 PM
It's quite hard to debug such scripts if you can't mindread.

Nevertheless, all I can do is random guessing and say that your form has not the name "formname" and the input element you work on has not the name "fieldname", before you tell us a little bit more about the actual validation script.

marvinmartian
07-26-2002, 12:17 PM
Yes, of course......below is the script in question and the form to which it refers. Hopefully, this will give you the added info you were looking for.

Thanks!

<!--Begin registration form validation-->

function RegisterValid()
{
validMessage="Please complete the following field(s):\n\n";
dataEntered = new Boolean(true)
if(document.register.firstname.value=="")
{
dataEntered = false;
validMessage += "First Name\n";
}
if(document.register.lastname.value=="")
{
dataEntered = false;
validMessage += "Last Name\n";
}
if(document.register.street1.value=="")
{
dataEntered = false;
validMessage += "Street Address\n";
}
if(document.register.street2.value=="")
{
dataEntered = false;
validMessage += "Street Address 2\n";
}
if(document.register.city.value=="")
{
dataEntered = false;
validMessage += "City\n";
}
if(document.register.states.value=="")
{
dataEntered = false;
validMessage += "State\n";
}
if(document.register.zipcode.value.length!=5)
{
dataEntered = false;
validMessage += "Zip\n";
}
if(document.register.email.value=="")
{
dataEntered = false;
validMessage += "E-Mail Address\n";
}
if(document.register.userid.value=="")
{
dataEntered = false;
validMessage += "Userid\n";
}
if(document.register.password.value=="")
{
dataEntered = false;
validMessage += "Password\n";
}
if(document.register.password2.value=="")
{
dataEntered = false;
validMessage += "Re-enter Password\n";
}
if(dataEntered==false)
{
alert(validMessage);
return false;
}
else
{
if(document.register.password.value != document.register.password2.value)
{
alert("You have entered two different passwords!");
return false;
}
else
{
return true;
}
}
}

<!--End registration form validation-->

<table align="center">

<form name="register" method="POST" action="" onSubmit="return RegisterValid()">
<tr>
<td>First Name: </td>
<td><input name=firstname type=text size=30 maxlength=20></td>
</tr>
<tr>
<td>Last Name: </td>
<td><input name=lastname type=text size=30 maxlength=20></td>
</tr>
<tr>
<td>Street Address: </td>
<td><input name=street1 type=text size=30 maxlength=30></td>
</tr>
<tr>
<td>Street Address 2: </td>
<td><input name=street2 type=text size=30 maxlength=30></td>
</tr>
<tr>
<td>City: </td>
<td><input name=city type=text size=30 maxlength=20></td>
</tr>
<tr>
<td>State: </td>
<td><select name=states size=1>
<option selected>Please Select a State</option>
<option value="Alabama">AL</option>
<option value="Alaska">AK</option>
<option value="Arizona">AZ</option>
<option value="Arkansas">AR</option>
<option value="California">CA</option>
<option value="Colorado">CO</option>
<option value="Connecticut">CT</option>
<option value="Delaware">DE</option>
<option value="District of Columbia">DC</option>
<option value="Florida">FL</option>
<option value="Georgia">GA</option>
<option value="Hawaii">HI</option>
<option value="Idaho">ID</option>
<option value="Illinois">IL</option>
<option value="Indiana">IN</option>
<option value="Iowa">IA</option>
<option value="Kansas">KS</option>
<option value="Kentucky">KY</option>
<option value="Louisiana">LA</option>
<option value="Maine">ME</option>
<option value="Maryland">MD</option>
<option value="Massachusetts">MA</option>
<option value="Michigan">MI</option>
<option value="Minnesota">MN</option>
<option value="Mississippi">MS</option>
<option value="Missouri">MO</option>
<option value="Montana">MT</option>
<option value="Nebraska">NE</option>
<option value="Nevada">NV</option>
<option value="New Hampshire">NH</option>
<option value="New Jersey">NJ</option>
<option value="New Mexico">NM</option>
<option value="New York">NY</option>
<option value="North Carolina">NC</option>
<option value="North Dakota">ND</option>
<option value="Ohio">OH</option>
<option value="Oklahoma">OK</option>
<option value="Oregon">OR</option>
<option value="Pennsylvania">PA</option>
<option value="Rhode Island">RI</option>
<option value="South Carolina">SC</option>
<option value="South Dakota">SD</option>
<option value="Tennessee">TN</option>
<option value="Texas">TX</option>
<option value="Utah">UT</option>
<option value="Vermont">VT</option>
<option value="Virginia">VA</option>
<option value="Washington">WA</option>
<option value="West Virginia">WV</option>
<option value="Wisconsin">WI</option>
<option value="Wyoming">WY</option>
</select></td>
</tr>
<tr>
<td>Zip: </td>
<td><input name=zipcode type=text size=30 maxlength=10></td>
</tr>
<tr>
<td>E-mail Address: </td>
<td><input name=email type=text size=30 maxlength=30></td>
</tr>
<tr>
<td>Userid: </td>
<td><input name=userid type=text size=30 maxlength=30></td>
</tr>
<tr>
<td>Password: </td>
<td><input name=password type=text size=30 maxlength=12></td>
</tr>
<tr>
<td>Re-enter Password: </td>
<td><input name=password2 type=text size=30 maxlength=12></td>
</tr>
</table>
<table align="center">
<tr>
<td><input type="reset" value="Clear"></td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>

mordred
07-26-2002, 01:09 PM
Hmh... I tested the code above in IE5.5 on Win2k, and everything worked just fine... have I overseen the obvious? :confused:

Actually, the script worked pretty good. It checked each form element if it was filled with at least one character, and if the passwords were the same, and if zipcode had 5 characters. Perhaps I would adjust the maxlength attribute for "zipcode" to 5 so that not more characters could be entered, but that's just a very very minor flaw.

Are you sure that the page in question does contain exactly this code? Sometimes, IE is very picky about refreshing content that was previously in the cache. Usually clearing the temporary internet files helps in this case.

If the problem still persists, I'll think you have to elaborate more on the error messages you get. You know, after which action do they appear, and on which platform did you test. Although I didn't find anything in the code that made this script incompatible to other platforms...

marvinmartian
07-26-2002, 04:38 PM
Thank you for testing the script and giving my your thoughts on things. I am testing it on IE 5.0 and Netscape 4.7. Again, it works perfectly in NS, but does not work in IE 5.0. I only posted the effected pieces of the HTML for you to see. If you'd like, and/or have the time, could I mail you the full page to test?

Thanks again

mordred
07-26-2002, 05:31 PM
Better it is to post a link to the page, so I can view when I'm monday again at work, there I'll have also IE5.0 ready for tests.

That's still strange IMHO... I can't see any code that's not recognized by IE5.0... let's see.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum