home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 2692
Discussions: 186,607, Posts: 2,227,049, Members: 230,241
Free Scan: Update Your PC's Outdated Drivers to Optimize Performance
Old June 26th, 2008, 10:28 PM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Jun 2008
Posts: 1
Smile
javascript problem

i have created a form in html but can't seem to validate all the requires files and its not validating at all.
The things i need sto validate is name, address, suburb, postcode which must be numerical and 4 dits, email valiadtion with ampersand, card type and month and year. please help

here is the script for html and external java script

HTml File

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Joe's Fruit and Vegetables</title>
<link rel="stylesheet" type="text/css" href="../css/joe_style.css" />
<script language="javascript1.5" src="../javascript/joes.js"></script>
</head>

<body>
<form id="orderform" name="orderform" method="post" onsubmit="return ValidateInputs()">
<p><strong>Your Details</strong></p>
<p>A * means you must fill in all the details</p>
<p>
<label for="Name">*Name:</label>
<input name="Name" type="text" id="Name" accesskey="N" tabindex="1" value="full name required" size="45" maxlength="25" />
</p>
<p>
<label>*Address:
<input name="address" type="text" id="address" accesskey="a" tabindex="2" value="Address Required" size="60" maxlength="60" />
</label>
</p>
<p>
<label>*Suburb:
<input name="suburb" type="text" id="suburb" accesskey="s" tabindex="3" value="Suburb Required" size="25" maxlength="25" />
</label>&nbsp; &nbsp;
<label>*Postcode:
<input name="postcode" type="text" id="postcode" accesskey="p" tabindex="6" value=" Required" size="12" maxlength="10" />
</label>
</p>
<p>
<label>*Email Address:
<input name="emailaddress" type="text" id="emailaddress" accesskey="e" tabindex="7" value="Email Required" size="75" maxlength="60" />
</label>
</p>
<p>
<label>Order:<br />
<textarea name="order" cols="70" rows="6" id="order" accesskey="o" tabindex="8">Put your orders in here</textarea>
</label>
</p>
<p>Credit Card Details:</p>
<p>
<label>*Type:
<select name="type" size="1" id="type" accesskey="t" tabindex="9">
<option selected="selected">Amex</option>
<option>Visa</option>
<option>Diners</option>
<option>Mastercard</option>
</select>
</label>
&nbsp;
<label>*Expiry Date: </label>
<label>
<select name="month" size="1" id="month" accesskey="m" tabindex="11">
<option selected="selected">01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
</select>
</label>
<label>
<select name="year" size="1" id="year" accesskey="y" tabindex="12">
<option>2008</option>
<option>2009</option>
<option>2010</option>
<option>2011</option>
<option>2012</option>
<option>2013</option>
<option>2014</option>
<option>2015</option>
</select>
</label>
</p>
<p>
<label>
<input type="submit" name="submit" id="submit" value="Submit" accesskey="u" tabindex="13" />
</label>
<label>
<input type="reset" name="clear" id="clear" value="Clear" accesskey="c" tabindex="14" />
</label></p>
<tr>
<th width="80" scope="col"><label for="Submit"></label></th>
<th width="72" scope="col"><label for="label4"></label></th>
</tr>
</form>

</div>
</body>
</html>

External Java Script

function ValidateInputs() {
var sName = oredrform.full_name.value;
var sAddress = orderform.address.value;
var sSuburb = oredrform.suburb.value;
var sPostCode = orderform.PostCode.value;
var sEmail = oredrform.email.value;
var sCredit_card = orderform.credit_card.value;
var sMonth = orderform.month.value;
var sErr = "";
var sInstr = "";

//Check the fields
if (sName == "") {
sErr = "You must enter a full name\n";
}

if (sAddress == "") {
sErr = sErr + "You must enter an address\n";
}

if (sSuburb == "") {
sErr = sErr + "You must enter a Suburb\n";
}

if (sPostCode == "") {
sErr = sErr + "You must enter a Postal Code\n";
}

if (sEmail == "") {
sErr = sErr + "You must enter an email address\n";
}

if (sCredit_card == "please_choose") {
sErr = sErr + "You must select a credit card type\n";
}

if (sMonth == "00") {
sErr = sErr + "You must select a month\n";
}



if (sErr == "") {
return true;
}
else {
sInstr = "The following errors were found with your submission."
sInstr = sInstr + "\nPlease correct them and try again.\n\n"
sErr = sInstr + sErr

//inform the user of the problem
alert(sErr);
return false;
}

}

bhas is offline   Reply With Quote
TechIMO.com Ads - Login or register for less ads.
How many errors does your computer have?

You no longer need to guess! This free stability scan and registry cleaner download will give you a complete diagnosis of your Windows registry, identifying errors and conflicts.

FREE instant scan


Guest, Register Free! to remove this ad and get your tech support questions answered in minutes!
Old June 28th, 2008, 07:32 AM     #2 (permalink)
Senior Member
 
Join Date: May 2003
Location: Aus, Gold Coast :)
Posts: 793
Send a message via ICQ to exally
two things you might want to try... instead of using orderform.<element name> use document.getElementById(<id>).value
also, you could pass the form to function using "return ValidateInputs(this)".

ValidateInputs(form)
{
form.<element name>
}


also you are setting values in all of your input field and then calling value == "" so it would never be so?! maybe.,.. i haven't tested any of this.


Last edited by exally : June 28th, 2008 at 07:35 AM.
exally is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
javascript function problem csamuels Webmastering and Programming 1 October 11th, 2006 03:35 PM
Javascript problem herronial Webmastering and Programming 0 October 19th, 2005 04:48 AM
Javascript problem with Firefox Iturea Webmastering and Programming 3 October 17th, 2005 09:55 AM
javascript onmouseover problem soma104 Webmastering and Programming 1 October 17th, 2005 03:19 AM
JavaScript Problem MPAnsaldi84 Webmastering and Programming 0 April 22nd, 2004 11:23 PM

Most Active Discussions
Is It Just Me? (528)
Misery Loves Company... (1849)
Why Does the MOON Grow Bigger as It.. (18)
heatsink issue (10)
New Mobo (18)
UPGRADING C/D DRIVE TO 250GB & .. (14)
SSD's, RAID, and External Backup (7)
1 internet. 1 house. 3 computer. ho.. (13)
Is This A Compatible Gaming PC? (18)
Recent Discussions
system restore 'next' button wo.. (1)
firewall (1)
C++ compiler suggestions (4)
Official World of Warcraft Thre.. (4529)
Programming question (2)
UPGRADING C/D DRIVE TO 250GB &a.. (14)
Ubuntu or Xubuntu....anyone!!? (7)
Building my first PC and need s.. (0)
PNY vs Gainward (3)
FS: Dell 6000 laptop, modded 36.. (2)
Apple iPod touch 16 GB $200 (4)
Six 28-Disc Cross Design Black .. (4)


All times are GMT -4. The time now is 12:02 PM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28