473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Form Validation is not working

Hi

I am using this form and want to validate the form using java script when i click on the submit button it does not do anyaction Is there anything wrong with this code.

Plz help



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Java Script Form Validation example</title>
<link rel="STYLESHEET" type="text/css" href="/style/jsc.css">

</head>
<body>
<form action="" name="myform" >
<table cellspacing="2" cellpadding="2" border="0">
<tr>
<td align="right">First Name</td>

<td><input type="text" name="FirstName"></td>
</tr>
<tr>
<td align="right">Last Name</td>
<td><input type="text" name="LastName"></td>
</tr>
<tr>
<td align="right">EMail</td>
<td><input type="text" name="Email"></td>
</tr>

<tr>
<td align="right">Phone</td>
<td><input type="text" name="Phone"></td>
</tr>
<tr>
<td align="right">Address</td>
<td><textarea cols="20" rows="5" name="Address"></textarea></td>
</tr>
<tr>
<td align="right">Country</td>

<td>
<SELECT name="Country">
<option value="" selected>[choose yours]
<option value="008">Albania</option>
<option value="012">Algeria</option>
<option value="016">American Samoa</option>
<option value="020">Andorra</option>
<option value="024">Angola</option>
<option value="660">Anguilla</option>
<option value="010">Antarctica</option>
<option value="028">Antigua And Barbuda</option>
<option value="032">Argentina</option>
<option value="051">Armenia</option>
<option value="533">Aruba</option>
</SELECT>

</td>
</tr>
<tr>
<td align="right"></td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
<script language="JavaScript" type="text/javascript">
//You should create the validator only after the definition of the HTML form
var frmvalidator = new Validator("myform");
frmvalidator.addValidation("FirstName","req","Plea se enter your First Name");
frmvalidator.addValidation("FirstName","maxlen=20" ,
"Max length for FirstName is 20");
frmvalidator.addValidation("FirstName","alpha");

frmvalidator.addValidation("LastName","req");
frmvalidator.addValidation("LastName","maxlen=20") ;

frmvalidator.addValidation("Email","maxlen=50");
frmvalidator.addValidation("Email","req");
frmvalidator.addValidation("Email","email");

frmvalidator.addValidation("Phone","maxlen=50");
frmvalidator.addValidation("Phone","numeric");

frmvalidator.addValidation("Address","maxlen=50");
frmvalidator.addValidation("Country","dontselect=0 ");

</script>
</body>
</html>
Dec 22 '06 #1
3 2707
b1randon
171 Expert 100+
Hi

I am using this form and want to validate the form using java script when i click on the submit button it does not do anyaction Is there anything wrong with this code.

Plz help



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Java Script Form Validation example</title>
<link rel="STYLESHEET" type="text/css" href="/style/jsc.css">

</head>
<body>
<form action="" name="myform" >
<table cellspacing="2" cellpadding="2" border="0">
<tr>
<td align="right">First Name</td>

<td><input type="text" name="FirstName"></td>
</tr>
<tr>
<td align="right">Last Name</td>
<td><input type="text" name="LastName"></td>
</tr>
<tr>
<td align="right">EMail</td>
<td><input type="text" name="Email"></td>
</tr>

<tr>
<td align="right">Phone</td>
<td><input type="text" name="Phone"></td>
</tr>
<tr>
<td align="right">Address</td>
<td><textarea cols="20" rows="5" name="Address"></textarea></td>
</tr>
<tr>
<td align="right">Country</td>

<td>
<SELECT name="Country">
<option value="" selected>[choose yours]
<option value="008">Albania</option>
<option value="012">Algeria</option>
<option value="016">American Samoa</option>
<option value="020">Andorra</option>
<option value="024">Angola</option>
<option value="660">Anguilla</option>
<option value="010">Antarctica</option>
<option value="028">Antigua And Barbuda</option>
<option value="032">Argentina</option>
<option value="051">Armenia</option>
<option value="533">Aruba</option>
</SELECT>

</td>
</tr>
<tr>
<td align="right"></td>
<td><input type="submit" value="Submit"></td>
</tr>
</table>
</form>
<script language="JavaScript" type="text/javascript">
//You should create the validator only after the definition of the HTML form
var frmvalidator = new Validator("myform");
frmvalidator.addValidation("FirstName","req","Plea se enter your First Name");
frmvalidator.addValidation("FirstName","maxlen=20" ,
"Max length for FirstName is 20");
frmvalidator.addValidation("FirstName","alpha");

frmvalidator.addValidation("LastName","req");
frmvalidator.addValidation("LastName","maxlen=20") ;

frmvalidator.addValidation("Email","maxlen=50");
frmvalidator.addValidation("Email","req");
frmvalidator.addValidation("Email","email");

frmvalidator.addValidation("Phone","maxlen=50");
frmvalidator.addValidation("Phone","numeric");

frmvalidator.addValidation("Address","maxlen=50");
frmvalidator.addValidation("Country","dontselect=0 ");

</script>
</body>
</html>
I don't know where you got this code but it looks like you're trying to use a library someone has put together that has a Validator object in it:

Expand|Select|Wrap|Line Numbers
  1. var frmvalidator = new Validator("myform");
  2.  
If you want to use this object you'll need to include the constructor for it. Otherwise, you're missing the code do to validation. You can find some validation code here.
Dec 22 '06 #2
AricC
1,892 Expert 1GB
For what you are trying to validate you don't need some huge class. Just check that the fields are filled in and something is selected in the drop down. The link brandon post should be more than sufficient.
Dec 22 '06 #3
b1randon
171 Expert 100+
For what you are trying to validate you don't need some huge class. Just check that the fields are filled in and something is selected in the drop down. The link brandon post should be more than sufficient.
Yes, AricC is right. It would be better for you to build the simple validation that like that found on my link than to try to integrate some pre-built class. Thanks for the thought AricC!
Dec 22 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: TG | last post by:
Dear PHP Group, I have two forms that are used to collect user information. The first one takes user inputted values such as fullname, city, address etc. I want these values to display in the...
12
by: CJ | last post by:
Why won't this work? I am passing the name of the form (I have two that use this validation script) but I keep getting an error. Error reads: "document.which_form.name is null or not an object" ...
4
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a...
3
by: Skippytpe | last post by:
Does anyone have an idea why the form validation in the following page wouldn't be working? I had been using XHTML 1.0 transitional which allowed me to use the form attribute 'name.' I could then...
6
by: Darren | last post by:
I have a form that has 10 fields on it. I have made all of them "Required". I also am using vb if statements to decide whether or not each field should be on the page. I am using the vb to...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
2
scubak1w1
by: scubak1w1 | last post by:
Hello, I am building a form that collects some data about a file and throws it into a PosgreSQL database and also allows the user to upload and process the file using PHP's $_FILES... i.e.,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.