473,473 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Validating a form

8 New Member
Using javascripts to validate this form.

Basic operation, when a user clicks the submit order button, the javascript code must validate everything entered by the user.

Please help finnish this form.

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Purchase Order</title>
<script language="javascript">
<!--Hide from old browsers
function Validate(myform) {
var OrdFisrtName = document.Order.FirstName.value
if (OrdFisrtName == " ") {
alert("Please enter your First Name")
document.Order.FirstName.value = " "
document.Order.FirstName.focus()
}
else {
var OrdLastName = document.Order.LastName.value
if (OrdLastName == " ") {
alert("Please enter you Last Name")
document.Order.LastName.value = " "
document.Order.LastName.focus()
}
else {
var OrdAddress1 = document.Order.Address1.value
if (OrdAddress1 == " ") {
alert("Please enter your 1st Street Address")
document.Order.Address1.value = " "
document.Order.Address1.focus()
}
else {
var OrdAddres2 = document.Order.Address2.value
if (OrdAddres2 == " ") {
alert("Please enter your 2nd Street Address")
document.Order.Address2.value = " "
document.Order.Address2.focus()
}
else {
var OrdCity = document.Order.City.value
if (OrdCity == " ") {
alert("Please enter your City")
document.Order.City.value = " "
document.Order.City.focus()
}
else {
var OrdState = document.Order.State.value
var OrdState = parseInt(OrdState,10)
if (isNaN(OrdState)) {
alert("Invalid State, your State must be numeric")
document.Order.State.value = " "
document.Order.State.focus()
}
else {
var OrdZip = document.Order.Zip.value
var OrdZip = parseInt(OrdZip,10)
if (isNaN(OrdZip)) {
alert("Invalid Zip, your Zip must be numeric")
document.Order.Zip.value = " "
document.Order.Zip.focus()
}
else {
var OrdPhone = document.Order.Phone.value
var OrdPhone = parseInt(OrdPhone,10)
if (isNaN(OrdPhone)) {
alert("Invalid Phone Number, your Phone Number must be numeric(e.g:0723835373)")
document.Order.Phone.value = " "
document.Order.Phone.focus()
}
else {
var OrdFax = document.Order.Fax.value
var OrdFax = parseInt(OrdFax,10)
if (isNaN(OrdFax)) {
alert("Invalid Fax Number, your Fax Number must be numeric(e.g:012 429 3221)")
document.Order.Fax.value = " "
document.Order.Fax.focus()
}
else {
var OrdCredit = document.Order.Credit.value
var OrdCredit = parseInt(OrdCredit ,10)
if (isNaN(OrdCredit)) {
alert("Invalid Credit Card Number, your Credit Card Number must be numeric")
document.Order.Credit.value = " "
document.Order.Credit.focus()
}
}
}
}
}
}
}
}
}
}
}


//-->
</script>
</head>
<body>
<form name="Order" action="http://www.scsite.com" method="post" enctype="text/plain">
<table border="0" width="584" height="1017">
<tr>
<td height="1011" width="574">
<h1>Purchase Order</h1>

<h2>Products</h2>

<p>Hand Tools &nbsp;<select name="Hand">
<option>Hand Tool &nbsp;
<option>Hammer
<option>Wrenhes
</select>
Power Tools &nbsp;<select name="Power">
<option>Power Tool &nbsp;
<option>Drill Machine
<option>Jigsaw
</select>
Building Materials &nbsp;<select name="Builing">
<option>Materials
<option>Plywood
<option>Shingles
<option>Nails
<option>Screws
</select>

</p>

<h2>Customer Information</h2>
<p>First Name &nbsp;<input type="text" name="FirstName" value=" "> Last Name &nbsp;<input type="text" name="LastName" value=" "></p>

<p>Street Address 1 &nbsp;<input type="text" name="Address1" size="49" value=" "></p>
<p>Street Address 2 &nbsp;<input type="text" name="Address2" size="49" value=" "></p>

<p>City &nbsp;<input type="text" name="City" size="30" value=" "> State &nbsp;<input type="text" name="State" size="6" value=" ">
Zip &nbsp;<input type="text" name="Zip" size="10" value=" ">
</p>

<p>Phone &nbsp;<input type="text" name="Phone" value=" "> Fax &nbsp;<input type="text" name="Fax" value=" "></p>

<p>Payment Method? &nbsp;<input type="radio" name="test" value="Visa" onclick="document.Order.Credit.focus()">Visa <input type="radio" name="test" value="Master" onclick="document.Order.Credit.focus()">Master Card
<input type="radio" name="test" value="American" onclick="document.Order.Credit.focus()">American Express
</p>

<p>Credit Card Number &nbsp; <input type="text" name="Credit" size="49" value=" "></p>

<p>Expiration Month &nbsp;<select name="Month">
<option>Month&nbsp;
<option>Jan
<option>Feb
<option>Mar
<option>Apr
<option>May
<option>Jun
<option>Jul
<option>Aug
<option>Sep
<option>Oct
<option>Nov
<option>Dec
</select>
Expiration Year &nbsp;<select name="Year">
<option>Year&nbsp;
<option>2005
<option>2006
<option>2007
<option>2008
<option>2009
<option>2010
<option>2011
<option>2012
<option>2013
<option>2014
<option>2015
</select>
</p>

<h2>Shipping Information</h2>

<p>Click here if shipping information is different from the billing information. &nbsp;<input type="checkbox" name="checkInfo" value="true" onclick="document.Order.First.focus()"></p>

<p>First Name &nbsp;<input type="text" name="First" value=" "> Last Name &nbsp;<input type="text" name="Last" value=" "></p>

<p>Street Address 1 &nbsp;<input type="text" name="Addr1" size="49" value=" "></p>
<p>Street Address 2 &nbsp;<input type="text" name="Addr2" size="49" value=" "></p>

<p>City &nbsp;<input type="text" name="City1" size="30" value=""> State &nbsp;<input type="text" name="State1" size="6" value=" ">
Zip &nbsp;<input type="text" name="Zip1" size="10" value="">
</p>

<p>Phone &nbsp;<input type="text" name="Phone1" value=" "> Fax &nbsp;<input type="text" name="Fax1" value=" "></p>

<p><input type="button" value="Submit Order" onclick="Validate(Order)"></p>

<h2>Office Use Only</h2>

<p>Product Shipped to customer? &nbsp;<input type="radio" name="test" value="Yes" onclick="document.Order.Date.focus()">Yes <input type="radio" name="test" value="No">No</p>

<p>Date Shipped &nbsp;<input type="text" name="Date" value=" "></p>
<p>&nbsp;</td>
</tr>
</table>
</form>
</body>
</html>
Jun 15 '07 #1
2 2164
gits
5,390 Recognized Expert Moderator Expert
hi ...

there are some things to mention i think: first of all have a look at the correct if-statement-usage:

Expand|Select|Wrap|Line Numbers
  1. if (cond == true) {
  2.     // do this
  3. } else {
  4.     // do that
  5. }
  6.  
its a binary statement that only decides between true and false ... so you cannot put an other else but you can:

Expand|Select|Wrap|Line Numbers
  1. if (cond == true) {
  2.     // do this
  3. } else if (cond1 == true) {
  4.     // do that
  5. } else if (cond2 == true) {
  6.     // do this+that
  7.  
the other thing is more like a question ... you want to check all textboxes contained by your form and you have empty or numeric checks? in that case you would better give your textboxes custom attributes like must="true" value_type="numeric" and loop through all textboxes ... and call the checks dependend to your attributes ...

kind regards ...
Jun 15 '07 #2
SONIQ
8 New Member
hi ...

there are some things to mention i think: first of all have a look at the correct if-statement-usage:

Expand|Select|Wrap|Line Numbers
  1. if (cond == true) {
  2.     // do this
  3. } else {
  4.     // do that
  5. }
  6.  
its a binary statement that only decides between true and false ... so you cannot put an other else but you can:

Expand|Select|Wrap|Line Numbers
  1. if (cond == true) {
  2.     // do this
  3. } else if (cond1 == true) {
  4.     // do that
  5. } else if (cond2 == true) {
  6.     // do this+that
  7.  
the other thing is more like a question ... you want to check all textboxes contained by your form and you have empty or numeric checks? in that case you would better give your textboxes custom attributes like must="true" value_type="numeric" and loop through all textboxes ... and call the checks dependend to your attributes ...

kind regards ...
THANKS FOR YOUR HELP, I'M NOW HAVING A CLEAR PICTURE.
Jun 19 '07 #3

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

Similar topics

0
by: Bradley Bossard via DotNetMonster.com | last post by:
I am having an issue with the .NET framework (or C#) and validating events. I have implemented several validating event handlers for textboxes on a form. When I run the app, the form works...
2
by: Chris Dunaway | last post by:
I have a form with a textbox and numerous panels, buttons and other controls. I have handled the textbox Validating and Validated events. The textbox will hold a filename. In the validating...
0
by: Matthew | last post by:
All, I have searched google and the newsgroups but can't find anything the same as what I am experiencing (though I may have missed something). I have controls (textboxes) within UserControls...
0
by: Gary Shell | last post by:
I am experiencing some strange behavior between a UserControl's validating event and a treeview control. Initially, I thought it was related to an issue in the Knowledgebase article 810852...
21
by: Darin | last post by:
I have a form w/ a textbox and Cancel button on it. I have a routine to handle textbox.validating, and I have the form setup so the Cancel button is the Cancel button. WHen the user clicks on...
4
by: easoftware | last post by:
I am using VS .Net 2003 and VB. I have an app with one parent and two Mdi child forms. I need to validate data in the Mdi form. The Form.Validating event works when I try to close a Mdi form,...
16
by: Al Santino | last post by:
Hi, It appears displaying a messagebox in a validating event will cancel the subsequent event. In the program below, button 2's click event doesn't fire if you open a dialog box in button 1's...
1
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions...
8
by: Peted | last post by:
I have an amazing problem which i think i have no hope of solving Im working with a c# dot net module that is hosted by and runs under a delphi form envrioment. Dont ask me how this insanity has...
2
by: Peted | last post by:
Hi if i derive a reference to a control on a winform (ie Control activeControl = somecontrol on the form) how can i test if that control has a validating or validated event and more importantly...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.