| | |
Help
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2008
Posts: 4
Reputation:
Solved Threads: 0
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)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>U-Built-It Hardware Company</title> <script type="text/javascript"> <!-- Hide from incompatible browsers function validate( form ) { var nameField = form.firstname; if ( nameField.value == "" ) { alert('\nMissing Information!'); nameField.focus(); return false; } else { alert('\nDo the next stuff!'); return true; }} function Setshippinging(checked) { if (checked) { document.getElementById('ShippingAddress').value = document.getElementById('BillingAddress').value; document.getElementById('ShippingCity').value = document.getElementById('BillingCity').value; document.getElementById('ShippingState').value = document.getElementById('BillingState').value; document.getElementById('ShippingZip').value = document.getElementById('BillingZip').value; document.getElementById('ShippingCountry').value = document.getElementById('BillingCountry').value; } else { document.getElementById('ShippingAddress').value = ''; document.getElementById('ShippingCity').value = ''; document.getElementById('ShippingState').value = ''; document.getElementById('ShippingZip').value = ''; document.getElementById('ShippingCountry').value = ''; } } // Stop hiding from incompatible browsers --> </script> <style type="text/css"> hr.c2 {color: rgb(133,0,0); background-color: rgb(133,0,0); height: 1} td.c1 {font-family: sans-serif; font-size: large; font-weight: bold} </style> </head> <body> <form> <table> <tr> <td class="c1" colspan="2" width="100%"> <h1>U-Built-It Hardware Company</h1> </td> </tr> <tr> <td colspan="2"> <hr class="c2" /></td> </tr> <tr> <td class="c1" colspan="2" width="100%">Billing Information</td> </tr> <!-- Billing Information --> <tr> <td valign="top" colspan="2"> <table> <tr> <td> <form onreset="alert('The form will be reset')">Firstname: </td> <td><input type="text" name="fname" id="fname" size="30" /> <label for="lname">Last Name</label> <input type="text" name="lname" id="lname" size="30" /></td> </tr> <tr> <td><label for="address1">Address #1</label></td> <td><input type="text" name="address1" id="address1" size="60" /></td> </tr> <tr> <td></td> </tr> <tr> <td><label for="addess2">Address #2</label></td> <td><input type="text" name="address2" id="address2" size="60" /></td> </tr> <tr> <td><label for="city">City</label></td> <td><input type="text" name="city" id="city" size="40" /> <label for="state">State</label> <input type="text" name="state" id="state" size="3" /> <label for="zip">Zip</label> <input type="text" name="zip" id="zip" size="10" maxlength="10" /></td> </tr> <tr> <td><label for="country">Country</label></td> <td><input type="text" name="country" id="country" size="40" value="United States" /> <br /><br /> <input type="reset" value="Reset"> </td> </tr> </table> </td> </tr> <tr> <td colspan="2"> <hr class="c2" /></td> </tr> <tr> <td class="c1" colspan="2" width="100%">Shipping Information</td> </tr> <!-- Shipping Information --> <tr> <td colspan="2""></td> </tr> <tr> <td valign="top" colspan="2"> <input type="checkbox" onclick="SetShipping(this.checked);" />Same as Billing Address<br /> <table> <tr> <td> <form onreset="alert('The form will be reset')">Firstname: </td> <td><input type="text" name="fname1" id="fname1" size="30" /> <label for="lname1">Last Name</label> <input type="text" name="lname1" id="lname1" size="30" /></td> </tr> <tr> <td><label for="address">Address</label></td> <td><input type="text" name="address" id="address" size="60" /></td> </tr> <tr> <td></td> </tr> <tr> <td><label for="addess">Address</label></td> <td><input type="text" name="address" id="address" size="60" /></td> </tr> <tr> <td><label for="city2">City</label></td> <td><input type="text" name="city2" id="city2" size="40" /> <label for="state2">State</label> <input type="text" name="state2" id="state" size="3" /> <label for="zip2">Zip</label> <input type="text" name="zip2" id="zip2" size="10" maxlength="10" /></td> </tr> <tr> <td><label for="country2">Country</label></td> <td><input type="text" name="country2" id="country2" size="40" value="United States" /> <br /><br /> <input type="reset" value="Reset"> </form> </td> </tr> </table> </td> </tr> <tr> <td colspan="2"> <hr class="c2" /></td> </tr> <!-- Product Information --> <tr> <td class="c1" colspan="2" width="100%">Hand Tools</td> </tr> <tr> <td valign="top" colspan="2"> <table> <tr> <td width="100" valign="top" rowspan="2"><label for="item">Item Purchased</label></td> <td valign="top" rowspan="2"><select name="item" id="item"> <option>Planes</option> <option>Gouges</option> <option>Hammers</option> <option>Chisels</option> <option>Saws</option> <option>Screwdrivers</option> </select></td> </tr> <!-- Buttons --> <tr> <td valign="top colspan="2" align="center"> <form action="submitpage.htm" name="form1" onsubmit="return validate( this );" method="post"> <input type="submit" value="Submit" /> </form> </td> </tr> </table> </td> </tr> </table> </form> </body> </html>
Last edited by cscgal; Sep 26th, 2008 at 7:33 pm. Reason: Added code tags
I found several mistakes on your code..like:
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
•
•
•
•
<form onreset="alert('The form will be reset')">
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
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Firefox is checking my checkbox after a return false for validation
- Next Thread: adding,removing dynamic tables and validation
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxcode ajaxhelp ajaxjspservlets animate api automatically blackjack browser bug calendar captchaformproblem checkbox child class close cookies createrange() cursor dependent disablefirebug dom dropdown editor element engine events explorer ext file firehose flash form forms game google gxt hiddenvalue highlightedword html htmlform ie8 iframe image() images internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jump libcurl math matrixcaptcha media microsoft mp3 mysql object onerror onmouseoutdivproblem onreadystatechange parent passing paypal pdf php player post progressbar rated regex runtime scroll search security session shopping size software sql star stars stretch synchronous text textarea twitter unicode validation web website window windowsxp wysiwyg xspf \n






