codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  JavaScript form validation is not working. Can not figure out what`s wrong  rudy at 10:28 on Wednesday, February 25, 2004
 

Hi,

I have this form in asp. It works, except that the form validation does not seem to work. It is intended to do server-side form validation. I cann't figure out what is wrong. The file is an asp file. The validation function is in JavaScript. Here is the code:

html>
<head>
<title>Form</title>
<script language="JavaScript" type="text/javascript">
<!--
function validate(form){
if (form.FName.value == ""){
alert("You must enter a First Name.");
form.FName.focus();
return false;
}

if (form.LName == ""){
alert("You must enter a Last Name.");
form.LName.focus();
return false;
}
if (form.City == ""){
alert("You must enter a City.");
form.City.focus();
return false;
}
if (form.Country == ""){
alert("You must enter a Country.");
form.Country.focus();
return false;
}
if (form.SecretWord == ""){
alert("You must enter a Country.");
form.SecretWord.focus();
return false;
}
return true;
}

//-->
</script>
</head>
<body bgcolor="white" text="black">
<!-- Begin form code -->
<form name=form action=updatedatabase.asp method=post onsubmit="javascript:return validate(this)">

<input type="submit" name="submit" value="submit">

<br>
<i> Please, use the following format in entering your Mobile Number </i>
<br>
<i>(+CountryCode)AreaCode-999-9999</i>
<br>
<i><b>Example:</b></i>
<br>
<i>(+971)50-763-4167<i/>
<br>
<br>

<TABLE border="1">

<CAPTION><b>Subscribtion Service</b></CAPTION>

<TR><TH>First Name:</TH><TD>
<input type="text" name="FName" maxlength="20" size="20"></TD></TR>
<TR><TH>Last Name:</TH><TD>
<input type="text" name="LName" maxlength="20" size="20"></TD></TR>
<TR><TH>Mobile Number:</TH><TD>
<input type="text" name="MobilePhone" maxlength="20" size="20"></TD></TR>
<TR><TH>City:</TH><TD>
<input type="text" name="City" maxlength="20" size="20"></TD></TR>
<TR><TH>Country:</TH><TD>
<input type="text" name="Country" maxlength="20" size="20"></TD></TR>
<TR><TH>Secret Word:</TH><TD>
<input type="text" name="SecretWord" maxlength="20" size="20"></TD></TR>

</TABLE>


</form>
<!-- End form code -->
</body>
</html>

  Re: JavaScript form validation is not working. Can not figure out what`s wrong  Troy Wolf at 00:59 on Thursday, February 26, 2004
 

You are missing the ".value" for everything but the first element (FName) you test.
Troy Wolf: site expert
Shiny Solutions









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: onload event
•  Active Widgets
•  Re: onmouseover change image and text
•  Line Printer Interface
•  import contacts of msn/yahoo
•  Call windows apps from web apps
•  Re: ASP.NET web controls
•  netscape 6 browser problem
•  Re: Print .doc file from the website using System.Diagnostics.Process


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005