By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,287 Members | 1,544 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,287 IT Pros & Developers. It's quick & easy.

i want to validate the following code to ensure tha user enter first name, last name

P: 4
What do i add to this script to validate the entry?
Thanks in advance for the help.

Expand|Select|Wrap|Line Numbers
  1. <form name="continue" method="POST" action="shipping1.asp" onsubmit="return validate_form ();">
  2.       <input type="hidden" name="subhand" value="<%= subhand %>"><input type="hidden" name="subship" value="<%= subship %>"><input type="hidden" name="subquantity" value="<%= subquantity %>"><input type="hidden" name="subsize" value="<%= subsize %>"><input type="hidden" name="subtotal" value="<%= subtotal %>"><input type="hidden" name="subweight" value="<%= subweight %>"><div align="center"><center>
  3.         <table border="0" cellspacing="1" width="640" bordercolor="#808080" bordercolorlight="#C0C0C0" bordercolordark="#808080" cellpadding="4" style="border-collapse: collapse">
  4.         <tr>
  5.           <td bgcolor="#000000" colspan="4" align="center">
  6.           <font color="#FFFFFF"><img border="0" src="blank.gif"><strong><font face="Arial" size="2">FOR FUTURE 
  7.             ORDERS</font></strong></font></td>
  8.         </tr>
  9.         <tr>
  10.           <td bgcolor="#FFCC66" colspan="4" style="height: 37px">
  11.             <strong>
  12.             <font face="Arial" style="font-size: 9pt">Define
  13.             a Customer Password
  14.             </font></strong>
  15.             <font color="#000080" style="font-size: 9pt" face="Arial">
  16.             <input type="text" name="Password" size="20" value="<%= password%>" class="form_field"></font><font style="font-size: 9pt" face="Arial">&nbsp;&nbsp;&nbsp;&nbsp; </font>
  17.             <font color="#000080" style="font-size: 9pt" face="Arial">
  18.           <input type="checkbox" name="MailingList" value="Yes" checked><font style="font-size: 9pt" face="Arial"> </font></font>
  19.             <font style="font-size: 9pt" face="Arial">
  20.             Please Add me to your Mailing List</font></td>
  21.         </tr>
  22.         <tr>
  23.           <td bgcolor="#000080" width="20" rowspan="7" align="center"><strong>
  24.           <font face="Arial" size="3" color="#FFFFFF">S<br>
  25.           H<br>
  26.           I<br>
  27.           P</font></strong><p><strong>
  28.           <font face="Arial" size="3" color="#FFFFFF">T<br>
  29.           O</font></strong><p></td>
  30.           <td width="33%" valign="top" align="left" bgcolor="#E6E6E6"><strong>
  31.           <font size="1" color="#000080" face="Arial">Company
  32.           Name</font><font size="2" color="#00FF00" face="Arial"><br>
  33.             </font></strong>
  34.           <input name="shipcompany" size="23" value="<%= shipcompany%>" class="form_field"></td>
  35.           <td width="33%" valign="top" align="left" bgcolor="#E6E6E6">
  36.           <p class="form_field"><strong>
  37.           <font color="#000080" face="Arial" size="1">First
  38.           Name</font><font color="#00FF00" face="Arial" size="2"><br>
  39.             </font></strong>
  40.  
Aug 28 '09 #1
Share this Question
Share on Google+
5 Replies


gits
Expert Mod 5K+
P: 5,390
what have you done so far? i guess you already have a JavaScript-function called validate_form()?
Aug 29 '09 #2

P: 4
no haven't done that yet
Aug 31 '09 #3

gits
Expert Mod 5K+
P: 5,390
so start to implement something and post back with particular problems that occur during your efforts ...

kind regards
Aug 31 '09 #4

P: 4
i added this little bit of code before the <title>

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript">
  2. <!--
  3. function checkform ( form )
  4. {
  5.  
  6.   // ** START **
  7.   if (form.shipcompany.value == "") {
  8.     alert( "Please enter a Company Name." );
  9.     form.companyname.focus();
  10.     return false ;
  11.   }
  12.  
  13.   // ** END **
  14.   return true ;
  15. }
  16. //-->
  17. </script>
still allows empty fields
Aug 31 '09 #5

P: 4
Expand|Select|Wrap|Line Numbers
  1. <title>Order Details</title>
  2. <link rel="stylesheet" type="text/css" href="formpage.css">
  3. <style type="text/css">
  4. .style1 {
  5.     font-size: xx-small;
  6.     font-family: Arial;
  7. }
  8. </style>
  9. <head>
  10. <script type="text/javascript"><!--
  11.  
  12. function validateForm() {
  13. with (document.Continue) {
  14. var alertMsg = "The following REQUIRED fields\nhave been left empty:\n";
  15. if (shipfname.value == "") alertMsg += "\nPlease enter First Name";
  16. if (shiplname.value == "") alertMsg += "\nPlease enter Last Name";
  17. if (shipaddress.value == "") alertMsg += "\nPlease enter Shipping Address";
  18. if (shipzip.value == "") alertMsg += "\nPlease enter Zip Code";
  19. if (shipphone.value == "") alertMsg += "\nPlease enter Contact Number";
  20. if (shipemail.value == "") alertMsg += "\nPlease enter Email";
  21. if (alertMsg != "The following REQUIRED fields\nhave been left empty:\n") {
  22. alert(alertMsg);
  23. return false;
  24. } else {
  25. return true;
  26. } } }
  27. // --></script>
  28.  
  29.  
  30. <body bottommargin="0" leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" topmargin="0" bgcolor="#FFFFFF" link="#FF0000" vlink="#FF0000" alink="#FF0000">
  31.  
  32. <div align="center">
  33.   <center>
  34. <!--#include file="header_shop.inc"-->
  35.  
  36. <table border="0" cellpadding="0" cellspacing="0" width="100%" style="border-collapse: collapse" bordercolor="#111111">
  37.   <tr>
  38.     <td width="33%">
  39.           <p align="center">&nbsp;
  40.             </p>
  41.       <form name="continue" onsubmit="return validateForm()" method="POST " action="shipping1.asp">
  42.       <input type="hidden" name="subhand" value="<%= subhand %>"><input type="hidden" name="subship" value="<%= subship %>"><input type="hidden" name="subquantity" value="<%= subquantity %>"><input type="hidden" name="subsize" value="<%= subsize %>"><input type="hidden" name="subtotal" value="<%= subtotal %>"><input type="hidden" name="subweight" value="<%= subweight %>"><div align="center"><center>
  43.         <table border="0" cellspacing="1" width="640" bordercolor="#808080" bordercolorlight="#C0C0C0" bordercolordark="#808080" cellpadding="4" style="border-collapse: collapse">
  44.         <tr>
  45.           <td bgcolor="#000000" colspan="4" align="center">
  46.           <font color="#FFFFFF"><img border="0" src="blank.gif"><strong><font face="Arial" size="2">FOR FUTURE 
  47.             ORDERS</font></strong></font></td>
  48.         </tr>
  49.         <tr>
  50.           <td bgcolor="#FFCC66" colspan="4">
  51.             <strong>
  52.             <font face="Arial" style="font-size: 9pt">Define
  53.             a Customer Password
  54.             </font></strong>
  55.             <font color="#000080" style="font-size: 9pt" face="Arial">
  56.             <input type="text" name="Password" size="20" value="<%= password%>" class="form_field"></font><font style="font-size: 9pt" face="Arial">&nbsp;&nbsp;&nbsp;&nbsp; </font>
  57.             <font color="#000080" style="font-size: 9pt" face="Arial">
  58.           <input type="checkbox" name="MailingList" value="Yes" checked><font style="font-size: 9pt" face="Arial"> </font></font>
  59.             <font style="font-size: 9pt" face="Arial">
  60.             Please Add me to your Mailing List</font></td>
  61.         </tr>
  62.         <tr>
  63.           <td bgcolor="#000080" width="20" rowspan="7" align="center"><strong>
  64.           <font face="Arial" size="3" color="#FFFFFF">S<br>
  65.           H<br>
  66.           I<br>
  67.           P</font></strong><p><strong>
  68.           <font face="Arial" size="3" color="#FFFFFF">T<br>
  69.           O</font></strong><p></td>
  70.           <td width="33%" valign="top" align="left" bgcolor="#E6E6E6"><strong>
  71.           <font size="1" color="#000080" face="Arial">Company
  72.           Name</font><font size="2" color="#00FF00" face="Arial"><br>
  73.             </font></strong>
  74.           <input name="shipcompany" size="23" value="<%= shipcompany%>" class="form_field"></td>
  75.           <td width="33%" valign="top" align="left" bgcolor="#E6E6E6">
  76.           <p class="form_field"><strong>
  77.           <font color="#000080" face="Arial" size="1">First
  78.           Name</font><font color="#00FF00" face="Arial" size="2"><br>
  79.             </font></strong>
  80.           <input type="text" name="shipfname" size="23" value="<%= shipfname%>" class="form_field"></td>
  81.           <td width="33%" valign="top" align="left" bgcolor="#E6E6E6"><strong>
  82.           <font color="#000080" face="Arial" size="1">Last
  83.           Name</font><font color="#00FF00" face="Arial" size="2"><br>
  84.             </font></strong><font size="2" color="#00FF00" face="Arial">
  85.           <input type="text" name="shiplname" size="23" value="<%= shiplname%>" class="form_field"></font></td>
  86.         </tr>
  87.         <tr>
  88.           <td width="66%" valign="top" align="left" bgcolor="#E6E6E6" colspan="2"><strong>
  89.           <font size="1" color="#000080" face="Arial">Address</font><font size="2" color="#00FF00" face="Arial"><br>
  90.             </font></strong><font size="2" color="#00FF00" face="Arial">
  91.           <input type="text" name="shipaddress" size="52" value="<%= shipaddress%>" class="form_field"></font></td>
  92.           <td width="30%" valign="top" align="left" bgcolor="#E6E6E6">
  93.           <font face="Arial"><strong><font size="1" color="#000080">Email<br>
  94.             </font></strong></font>
  95.           <font size="2" color="#00FF00" face="Arial">
  96.           <input type="text" name="shipemail" size="23" value="<%= shipemail%>" class="form_field"></font></td>
  97.         </tr>
  98.         <tr>
  99.           <td width="30%" valign="top" align="left" bgcolor="#EEEEEE">
  100.           <font face="Arial"><strong><font size="1" color="#000080">City<br>
  101.             </font></strong></font>
  102.           <font size="2" color="#00FF00" face="Arial">
  103.           <input type="text" name="shipcity" size="23" value="<%= shipcity%>" class="form_field"></font></td>
  104.           <td width="30%" valign="top" align="left" bgcolor="#E6E6E6">
  105.           <strong><font size="1" color="#000080" face="Arial">State or Province<font color=red><B> * Required</B></font><br>
  106.           </font><font size="2" color="#00FF00" face="Arial">
  107. <%     If IsEmpty(shipstate) Or shipstate = "" Then
  108. %>
  109.           <select name="shipstate" size="1" class="form_field">
  110.             <option value="AL" selected>AL-Alabama</option>
  111.             <option value="AR">AR-Arkansas</option>
  112.             <option value="AZ">AZ-Arizona</option>
  113.             <option value="CA">CA-California</option>
  114.             <option value="CO">CO-Colorado</option>
  115.             <option value="CT">CT-Connecticut</option>
  116.             <option value="DC">DC-District of Columbia</option>
  117.             <option value="DE">DE-Delaware</option>
  118.             <option value="FL">FL-Florida</option>
  119.             <option value="GA">GA-Georgia</option>
  120.             <option value="HI">HI-Hawaii</option>
  121.             <option value="IA">IA-Iowa</option>
  122.             <option value="ID">ID-Idaho</option>
  123.             <option value="IL">IL-Illinois</option>
  124.             <option value="IN">IN-Indiana</option>
  125.             <option value="KS">KS-Kansas</option>
  126.             <option value="KY">KY-Kentucky</option>
  127.             <option value="LA">LA-Louisiana</option>
  128.             <option value="MA">MA-Massachusetts</option>
  129.             <option value="MD">MD-Maryland</option>
  130.             <option value="ME">ME-Maine</option>
  131.             <option value="MI">MI-Michigan</option>
  132.             <option value="MN">MN-Minnesota</option>
  133.             <option value="MO">MO-Missouri</option>
  134.             <option value="MS">MS-Mississippi</option>
  135.             <option value="MT">MT-Montana</option>
  136.             <option value="NC">NC-North Carolina</option>
  137.             <option value="ND">ND-North Dakota</option>
  138.             <option value="NE">NE-Nebraska</option>
  139.             <option value="NH">NH-New Hampshire</option>
  140.             <option value="NV">NV-Nevada</option>
  141.             <option value="NJ">NJ-New Jersey</option>
  142.             <option value="NM">NM-New Mexico</option>
  143.             <option value="NY">NY-New York</option>
  144.             <option value="OH">OH-Ohio</option>
  145.             <option value="OK">OK-Oklahoma</option>
  146.             <option value="OR">OR-Oregon</option>
  147.             <option value="PA">PA-Pennsylvania</option>
  148.             <option value="RI">RI-Rhode Island</option>
  149.             <option value="SC">SC-South Carolina</option>
  150.             <option value="SD">SD-South Dakota</option>
  151.             <option value="TN">TN-Tennessee</option>
  152.             <option value="TX">TX-Texas</option>
  153.             <option value="UT">UT-Utah</option>
  154.             <option value="VA">VA-Virginia</option>
  155.             <option value="VT">VT-Vermont</option>
  156.             <option value="WA">WA-Washington</option>
  157.             <option value="WI">WI-Wisconsin</option>
  158.             <option value="WV">WV-West Virginia</option>
  159.             <option value="WY">WY-Wyoming</option>
  160.                                                   </select> 
  161.           </font></strong>
  162. <%Else%>
  163. <font size="2">
  164.           <input type="text" name="shipstate" size="23" value="<%= shipstate%>" class="form_field"></font>
  165. <%End If%>          </td>
  166.           <td width="30%" valign="top" align="left" bgcolor="#E6E6E6"><strong>
  167.           <font color="#000080" face="Arial" size="1">Zip</font><font color="#00FF00" face="Arial" size="2"><br>
  168.             </font></strong><font size="2" color="#00FF00" face="Arial">
  169.           <input type="text" name="shipzip" size="23" value="<%= shipzip%>" class="form_field"></font></td>
  170.         </tr>
  171.         <tr>
  172.           <td width="32%" valign="top" align="left" bgcolor="#E6E6E6"><strong>
  173.           <font size="1" color="#000080" face="Arial">County</font><font size="2" color="#00FF00" face="Arial"><br>
  174.             </font></strong><font size="2" color="#00FF00" face="Arial">
  175.           <input type="text" name="shipcounty" size="23" value="<%= shipcounty%>" class="form_field"></font>
  176. </td>
  177.           <td width="30%" valign="top" align="left" bgcolor="#E6E6E6"><strong>
  178.           <font size="1" color="#000080" face="Arial">Telephone#</font><font size="2" color="#00FF00" face="Arial"><br>
  179.             </font></strong><font size="2" color="#00FF00" face="Arial">
  180.           <input type="text" name="shipphone" size="23" value="<%= shipphone%>"></font></td>
  181.           <td width="30%" valign="top" align="left" bgcolor="#E6E6E6"><strong>
  182.           <font color="#000080" face="Arial" size="1">Fax#</font><font color="#00FF00" face="Arial" size="2"><br>
  183.             </font></strong><font size="2" color="#00FF00" face="Arial">
  184.           <input type="text" name="shipfax" size="23" value="<%= shipfax%>"></font><table style="width: 100%">
  185.               <tr>
  186.                   <td style="height: 45px"><span class="style1"><strong>How did 
  187.                   you hear about us?</strong></span><br>
  188.                   <select name="How_did_u_hear_about_us" style="width: 168px">
  189.                   <option>None</option>
  190.                   <option>Exsisting Customer</option>
  191.                   <option>Wholesale Central</option>
  192.                   <option>Google</option>
  193.                   <option>Yahoo</option>
  194.                   <option>Inet</option>
  195.                   <option>Other</option>
  196.                   </select>&nbsp;</td>
  197.               </tr>
  198.           </table>
  199.             </td>
  200.         </tr>
  201.         <tr>
  202.           <td width="32%" valign="top" align="left" bgcolor="#E6E6E6"><strong>
  203.           <font size="1" color="#000080" face="Arial">Country</font><font size="2" color="#00FF00" face="Arial"><br>
  204.             </font></strong><font color="#00FF00" face="Arial"><%     If IsEmpty(shipcountry) Or shipcountry = "" Then
  205. %>
  206. <font size="2">
  207. <select NAME="shipcountry" size="1" class="form_field">
  208.             <option SELECTED VALUE="US">United States </option>
  209.           </select> </font></font>
  210. <%Else%>
  211. <font size="2">
  212.           <input type="text" name="shipcountry" size="23" value="<%= shipcountry%>" class="form_field"></font>
  213. <%End If%>
  214. </td>
  215.           <td width="30%" valign="top" align="left" bgcolor="#E6E6E6">
  216.     <strong><font face="Arial" size="1" color="#000080">Resale#</font><font size="2" color="#00FF00" face="Arial"><br>
  217.             </font></strong><font size="2" color="#00FF00" face="Arial">
  218.           <input type="text" name="shipresale" size="23" value="<%= shipresale%>"><br>
  219.     </font><b><font size="1" face="Arial">
  220.           CA Customers <u>MUST</u> provide their Resale Number</font></b></td>
  221.           <td width="30%" valign="top" align="left" bgcolor="#E6E6E6">
  222.           <font face="arial, helvetica ">
  223.           <strong><font color="#000080" size="1"><font color="#FF0000">
  224.           NO P.O. BOX SHIPPING PLEASE. </font><BR>The 48 US contiguous states (domestic) orders only - For 
  225.           Alaska, Hawaii, Virgin Islands, Puerto Rico, or International Orders, 
  226.     Please Email Us For Shipping Info: <a href="mailto:shipping@sharkeyes.com">shipping@sharkeyes.com</a>&nbsp;</font></strong></font></td>
  227.         </tr>
  228.  
  229. <!--      <tr>


Still no pop up alert. Can anyone tell me what's wrong?
Sep 2 '09 #6

Post your reply

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