943,910 Members | Top Members by Rank

Ad:
Sep 26th, 2008
0

Help

Expand Post »
I'm still new to JavaScript and I'm having trouble with an assignment. I can't seem to get my functions to work right for the alert to check for missing information when you submit the page and when you select the checkbox for the same as billing address? Thanks for the help!!

javascript Syntax (Toggle Plain Text)
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  4. <head>
  5. <title>U-Built-It Hardware Company</title>
  6.  
  7. <script type="text/javascript">
  8.  
  9. <!-- Hide from incompatible browsers
  10.  
  11. function validate( form )
  12. { var nameField = form.firstname;
  13. if ( nameField.value == "" ) { alert('\nMissing Information!');
  14. nameField.focus(); return false; }
  15. else { alert('\nDo the next stuff!');
  16. return true; }}
  17.  
  18. function Setshippinging(checked) {
  19. if (checked) {
  20. document.getElementById('ShippingAddress').value = document.getElementById('BillingAddress').value;
  21. document.getElementById('ShippingCity').value = document.getElementById('BillingCity').value;
  22. document.getElementById('ShippingState').value = document.getElementById('BillingState').value;
  23. document.getElementById('ShippingZip').value = document.getElementById('BillingZip').value;
  24. document.getElementById('ShippingCountry').value = document.getElementById('BillingCountry').value;
  25. } else {
  26. document.getElementById('ShippingAddress').value = '';
  27. document.getElementById('ShippingCity').value = '';
  28. document.getElementById('ShippingState').value = '';
  29. document.getElementById('ShippingZip').value = '';
  30. document.getElementById('ShippingCountry').value = '';
  31. }
  32. }
  33.  
  34.  
  35.  
  36.  
  37.  
  38. // Stop hiding from incompatible browsers -->
  39.  
  40. </script>
  41. <style type="text/css">
  42. hr.c2 {color: rgb(133,0,0); background-color: rgb(133,0,0); height: 1}
  43. td.c1 {font-family: sans-serif; font-size: large; font-weight: bold}
  44. </style>
  45. </head>
  46. <body>
  47. <form>
  48. <table>
  49. <tr>
  50. <td class="c1" colspan="2" width="100%">
  51. <h1>U-Built-It Hardware Company</h1>
  52. </td>
  53. </tr>
  54. <tr>
  55. <td colspan="2">
  56. <hr class="c2" /></td>
  57. </tr>
  58. <tr>
  59. <td class="c1" colspan="2" width="100%">Billing Information</td>
  60. </tr>
  61. <!-- Billing Information -->
  62.  
  63. <tr>
  64. <td valign="top" colspan="2">
  65. <table>
  66. <tr>
  67. <td>
  68. <form onreset="alert('The form will be reset')">Firstname:
  69. </td>
  70. <td><input type="text" name="fname" id="fname" size="30" /> <label for="lname">Last Name</label> <input type="text"
  71.  
  72. name="lname" id="lname" size="30" /></td>
  73. </tr>
  74. <tr>
  75. <td><label for="address1">Address #1</label></td>
  76. <td><input type="text" name="address1" id="address1" size="60" /></td>
  77. </tr>
  78. <tr>
  79. <td></td>
  80. </tr>
  81. <tr>
  82. <td><label for="addess2">Address #2</label></td>
  83. <td><input type="text" name="address2" id="address2" size="60" /></td>
  84. </tr>
  85. <tr>
  86. <td><label for="city">City</label></td>
  87. <td><input type="text" name="city" id="city" size="40" /> <label for="state">State</label> <input type="text" name="state"
  88.  
  89. id="state" size="3" /> <label for="zip">Zip</label> <input type="text" name="zip" id="zip" size="10" maxlength="10" /></td>
  90. </tr>
  91. <tr>
  92. <td><label for="country">Country</label></td>
  93. <td><input type="text" name="country" id="country" size="40" value="United States" />
  94. <br /><br />
  95. <input type="reset" value="Reset">
  96.  
  97. </td>
  98. </tr>
  99. </table>
  100. </td>
  101. </tr>
  102. <tr>
  103. <td colspan="2">
  104. <hr class="c2" /></td>
  105. </tr>
  106. <tr>
  107. <td class="c1" colspan="2" width="100%">Shipping Information</td>
  108. </tr>
  109. <!-- Shipping Information -->
  110. <tr>
  111. <td colspan="2&quot;"></td>
  112. </tr>
  113. <tr>
  114. <td valign="top" colspan="2">
  115.  
  116.  
  117.  
  118.  
  119. <input type="checkbox" onclick="SetShipping(this.checked);"
  120. />Same as Billing Address<br />
  121.  
  122. <table>
  123. <tr>
  124. <td>
  125. <form onreset="alert('The form will be reset')">Firstname:
  126. </td>
  127. <td><input type="text" name="fname1" id="fname1" size="30" /> <label for="lname1">Last Name</label> <input type="text"
  128.  
  129. name="lname1" id="lname1" size="30" /></td>
  130. </tr>
  131. <tr>
  132. <td><label for="address">Address</label></td>
  133. <td><input type="text" name="address" id="address" size="60" /></td>
  134. </tr>
  135. <tr>
  136. <td></td>
  137. </tr>
  138. <tr>
  139. <td><label for="addess">Address</label></td>
  140. <td><input type="text" name="address" id="address" size="60" /></td>
  141. </tr>
  142. <tr>
  143. <td><label for="city2">City</label></td>
  144. <td><input type="text" name="city2" id="city2" size="40" /> <label for="state2">State</label> <input type="text"
  145.  
  146. name="state2" id="state" size="3" /> <label for="zip2">Zip</label> <input type="text" name="zip2" id="zip2" size="10"
  147.  
  148. maxlength="10" /></td>
  149. </tr>
  150. <tr>
  151. <td><label for="country2">Country</label></td>
  152. <td><input type="text" name="country2" id="country2" size="40" value="United States" />
  153. <br /><br />
  154. <input type="reset" value="Reset">
  155. </form>
  156. </td>
  157. </tr>
  158. </table>
  159. </td>
  160. </tr>
  161. <tr>
  162. <td colspan="2">
  163. <hr class="c2" /></td>
  164. </tr>
  165.  
  166.  
  167.  
  168.  
  169. <!-- Product Information -->
  170. <tr>
  171. <td class="c1" colspan="2" width="100%">Hand Tools</td>
  172. </tr>
  173. <tr>
  174. <td valign="top" colspan="2">
  175. <table>
  176. <tr>
  177. <td width="100" valign="top" rowspan="2"><label for="item">Item Purchased</label></td>
  178. <td valign="top" rowspan="2"><select name="item" id="item">
  179. <option>Planes</option>
  180. <option>Gouges</option>
  181. <option>Hammers</option>
  182. <option>Chisels</option>
  183. <option>Saws</option>
  184. <option>Screwdrivers</option>
  185. </select></td>
  186. </tr>
  187.  
  188. <!-- Buttons -->
  189. <tr>
  190. <td valign="top colspan="2" align="center">
  191.  
  192.  
  193.  
  194. <form action="submitpage.htm" name="form1" onsubmit="return validate( this );" method="post">
  195. <input type="submit" value="Submit" />
  196.  
  197.  
  198.  
  199.  
  200. </form>
  201.  
  202. </td>
  203. </tr>
  204. </table>
  205. </td>
  206. </tr>
  207. </table>
  208. </form>
  209. </body>
  210. </html>
  211.  
Last edited by cscgal; Sep 26th, 2008 at 7:33 pm. Reason: Added code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pletch99 is offline Offline
4 posts
since Sep 2008
Sep 26th, 2008
0

Re: Help

Il work on your code if i get my time! Try to check it later!
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Sep 27th, 2008
0

Re: Help

I found several mistakes on your code..like:
Quote ...
<form onreset="alert('The form will be reset')">
where did you closed this form..
and i think you don't use form in another form..if you want use more forms in your page..use them after closing the first form..

And for all types of validations:
http://www.tizag.com/javascriptT/javascriptform.php
http://www.chrismcgrath.com/pagebuil...=53&partid=162
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008
Sep 27th, 2008
0

Re: Help

Hi there shanti! I know you can handle this thing! So i leave this up to you! Good day!
Featured Poster
Reputation Points: 114
Solved Threads: 138
Posting Shark
essential is offline Offline
973 posts
since Aug 2008
Sep 27th, 2008
0

Re: Help

try your side....
Reputation Points: 137
Solved Threads: 162
Posting Virtuoso
Shanti C is offline Offline
1,641 posts
since Jul 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Firefox is checking my checkbox after a return false for validation
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: adding,removing dynamic tables and validation





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC