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!

Can't get simple Javascript to work 1

Status
Not open for further replies.

Maldini

Technical User
Nov 10, 2002
55
0
0
GB
Hi,
I'm trying to do some simple form validation on an ASP page, but after trying for a couple of hours, it still doens't work.

This is the javascript function I have. When I pass a form as the checkForm variable, I do get alert boxes coming up, but they say 'undefined' instead of what I have.

<Script language="Javascript">

function Validate(checkForm) {

if (checkForm.Username.Value == "") {
alert('No User Name!');
return false;
} else {
alert(checkForm.UserName.Value);
}
return true;
}
</Script>

This is the HTML form; its wrapped in a number of divisions from CSS.

<FORM NAME="UserForm" Method="Post" Action="test.asp">
UserName:
<INPUT TYPE="text" Name="UserName"><BR>

<INPUT TYPE="button" Name="Add" Value="Add" onClick="Validate(document.UserForm)">
</FORM>

Any tips would be greatly appreciated; this problem has driven me mad; since its supposed to be so simple!

Thanks.
 

The main issue is that "Value" should have a lowercase "v" - JavaScript is case-sensitive.

You might also want to switch "document.UserForm" for "document.forms['UserForm']" and "checkForm.Username" for "checkForm.elements['Username']"

Hope this helps,
Dan


The answers you get are only as good as the information you give!

 
Thanks, solved the problem. It really was the capitalization of 'V' that caused the prob.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top