|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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: <input type='text' name='Oaddress' value='" & myRS("Address") & "'><br>" Response.Write "City: <input type='text' name='city' value='" & myRS("City") & "'><br>" Response.Write "Postcode: <input type='text' name='postcode' value='" & myRS("ZIP") & "'><br>" Response.Write "Country: <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"> </td> <td width="159"> </td> </tr> <tr> <td width="141">Credit Card Number: </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 : </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 : </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 |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
||||
|
||||
|
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 |
![]() |
| Viewing: ASP Free Forums > Programming > HTML, JavaScript And CSS Help > validating asp form with javasc. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|