HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 21st, 2004, 06:37 AM
macadam7 macadam7 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Southport
Posts: 18 macadam7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
validating asp form with javasc.

I am trying to validate the form below, but no prompts appear once the form is submitted. Any ideas? Thanks

<SCRIPT language="JavaScript">
<!--
function validateForm(form) // validate Survey data
{

if (!validateFirstName(form.firstName.value)) // first name valid?
{
form.firstName.focus()
return false
}
if (!validateLastName(form.lastName.value)) // last name valid?
{
form.lastName.focus()
return false
}
if (!validateAddress(form.address.value)) // address valid?
{
form.address.focus()
return false
}
if (!validateCity(form.city.value)) // city valid?
{
form.city.focus()
return false
}
if (!validatePostcode(form.postcode.value)) // postcode valid?
{
form.postcode.focus()
return false
}
if (!validateCountry(form.country.value)) // country valid?
{
form.country.focus()
return false
}
return true
}
function validateFirstName(firstName)
{
if (isBlank(firstName)) // first name field blank?
{
alert("Enter your first name, please!")
return false
}
if (firstName.indexOf(" ", 0) != -1) // two names?
{
alert("Enter one name only, please!")
return false
}
return true
}
function validateLastName(lastName)
{
if (isBlank(lastName)) // last name field blank?
{
alert("Enter your last name, please!")
return false
}
return true
}
function validateAddress(address)
{
if (isBlank(address)) // address field blank?
{
alert("Enter your address, please!")
return false
}
return true
}
function validateCity(city)
{
if (isBlank(city)) // city field blank?
{
alert("Enter your city, please!")
return false
}
return true
}
function validatePostcode(postcode)
{
if (isBlank(postcode)) // postcode name field blank?
{
alert("Enter your postcode, please!")
return false
}
return true
}
function validateCountry(country)
{
if (isBlank(country)) // country field blank?
{
alert("Enter your country, please!")
return false
}
return true
}

-->
</SCRIPT>
</head>

</head>

<body>
<!-- #include file="header.asp" -->

<div align="center">
<table width="600">
<tr>
<td width="600" valign="top">
<br>

<p>This page let's you confirm or change the shipping address to be used for this order, as well as provide your credit card information.</p>

<%
Dim Total, myRS, mySQL
Total = Request.QueryString("Total")
Set myRS = Server.CreateObject("ADODB.Recordset")
mySQL = "SELECT Carts.CartID, Customers.FName, Customers.LName, Customers.Address, Customers.City, Customers.ZIP, Customers.Country FROM Customers INNER JOIN Carts ON Customers.CustID = Carts.CustID WHERE Carts.CartID = " & CartID
myRS.Open mySQL, myConn

If myRS.EOF Then
Response.Write "<p>If you are a new customer! Please <a href='custform.asp?CartID=" & CartID & "'>sign-up</a> before checking out.</p>"

Response.Write "<p>If you are an existing customer! Please <a href='login.asp?CartID=" & CartID & "'>log-on</a> before checking out.</p>"


Else
Response.Write "<form action='payproc.asp?CartID=" & CartID & "' name='frmUser' method='post' onSubmit='justValidating=false; return validateForm(frmUser)'><br>"

Response.Write "<p class='text'>First Name:<input type='text' name='firstName' value='" & myRS("FName") & "'><br>"
Response.Write "Last Name:<input type='text' name='lastName' value='" & myRS("LName") & "'><br>"
Response.Write "Address: &nbsp;&nbsp;&nbsp;<input type='text' name='Oaddress' value='" & myRS("Address") & "'><br>"
Response.Write "City: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type='text' name='city' value='" & myRS("City") & "'><br>"
Response.Write "Postcode: &nbsp;<input type='text' name='postcode' value='" & myRS("ZIP") & "'><br>"
Response.Write "Country: &nbsp;&nbsp;<input type='text' name='country' value='" & myRS("Country") & "'></p>"

Response.Write "<p><b>Your order total is: £" & FormatNumber(Total,2) & "</b></p><p>This is the amount that will be debited to your credit card.</p>"
%>





<br>

<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" align="center" width="300" >
<tr>
<td width="141">&nbsp;&nbsp;</td>
<td width="159">&nbsp;&nbsp;</td>

</tr>
<tr>
<td width="141">Credit Card Number:&nbsp;&nbsp; </td>
<td width="159"> <input type="text" size="22" name="CardNo"></td>

</tr>
<tr>
<td width="141">Name on Credit Card: </td>
<td width="159"> <input type="text" size="22" name="CardName" value="" onChange="javascript:this.value=this.value.toLowerCase();"></td>
</tr>
<tr>
<td width="141">Card Type: </td>
<td width="159"><select size="1" name="CardType"><option selected="selected">Visa</option>
<option>Mastercard</option>
<option>Switch</option></select></td>
</tr>
<tr>
<td width="141">Expiry Month :&nbsp; </td>
<td width="159"> <select size="1" name="CardExpMonth"><option selected="selected">1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>11</option><option>12</option></select></td>
</tr>
<tr>
<td width="141">Expiry Year :&nbsp; </td>
<td width="159"> <select size="1" name="CardExpYear"><option selected="selected">2003</option><option>2004</option><option>2005</option><option>2006</option><option>2007</option><option>2008</option></select></td>
</td>
</tr>
</table>



<div><br>


Any additional comments?<br>
<br>
<textarea name="Comments" cols="40" rows="5"></textarea><br><br>
This is a final order confirmation. After the clicking the button below, your order will be complete.<br>
<br>
<input type="submit" value="Send Information"></div></form>

Last edited by macadam7 : February 21st, 2004 at 06:41 AM. Reason: wrong info enter

Reply With Quote
  #2  
Old February 21st, 2004, 10:33 AM
dcarva's Avatar
dcarva dcarva is offline
Contributing User
ASP Free Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 633 dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level)dcarva User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 9 h 18 m 20 sec
Reputation Power: 6
Hello,

There is a lot of code to look at here. What I would recommend is to debug the script:

1) Place an alert("test") as the first line of your function validateForm. This way, you know if it's even going to that function.

2) Place an alert before and after each IF statement. Write out the form field you are trying to validate.

This is a start.

Reply With Quote
  #3  
Old February 25th, 2004, 01:50 AM
Bullschmidt's Avatar
Bullschmidt Bullschmidt is offline
Guru
ASP Free Novice (500 - 999 posts)
 
Join Date: May 2003
Location: USA
Posts: 885 Bullschmidt User rank is Sergeant (500 - 2000 Reputation Level)Bullschmidt User rank is Sergeant (500 - 2000 Reputation Level)Bullschmidt User rank is Sergeant (500 - 2000 Reputation Level)Bullschmidt User rank is Sergeant (500 - 2000 Reputation Level)Bullschmidt User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 9 h 44 m 12 sec
Reputation Power: 23
In general I like to end each JavaScript line with a semi-colon.

Also here are some JavaScript form validation resources:

Javascript Field Validations -- Client Side Scripting by Nannette Thacker - 8/19/1999
http://www.shiningstar.net/articles...tions.asp?ID=AW

Form Validation Using Javascript - 9/19/1998
http://www.4guysfromrolla.com/webtech/091998-1.shtml
Good tips such as saving JavaScript functions in a file called DataValidation.js and including this in pages that need this.
JavaScript functions.

WebDaily: Your daily source for Web Technology Tips and Tricks! - 10/27/1998
http://www.4guysfromrolla.com/webtech/102798-1.shtml
Just checks if fields filled in.

Form Validation Scripts
http://www.coolnerds.com/jscript/formval.htm
__________________
J. Paul Schmidt
www.Bullschmidt.com - Freelance Web and Database Developer
www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingHTML, JavaScript And CSS Help > validating asp form with javasc.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not 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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT