If anyone can tell me why this stupid javascript isn't working, I'd greatly appreciate the help. It's driving me nuts. <html> <head> <script language='javascript'> <!--// function verifyform(){ if (document.ccpay.fname.value.length <= 0){ alert("Please enter the first name.\n"); document.ccpay.fname.focus(); return false; } if (document.ccpay.lname.value.length <= 0){ alert("Please enter the last name.\n"); document.ccpay.lname.focus(); return false; } if (document.ccpay.add1.value.length <= 0){ alert("Please enter the address.\n"); document.ccpay.add1.focus(); return false; } if (document.ccpay.city.value.length <= 0){ alert("Please enter the city.\n"); document.ccpay.city.focus(); return false; } if (document.ccpay.state.value.length <= 0){ alert("Please enter the state.\n"); document.ccpay.state.focus(); return false; } if (document.ccpay.zip.value.length < 4){ alert("Please enter the zipcode.\n"); document.ccpay.zip.focus(); return false; } if (document.ccpay.ccnum.value.length <= 0){ alert("Please enter the credit card number.\n"); document.ccpay.ccnum.focus(); return false; } if (document.ccpay.ccv.value.length <= 0){ alert("Please enter the cc verification number.\n"); document.ccpay.ccv.focus(); return false; } if (document.ccpay.card.selectedIndex <= 0){ alert("Please select one of the \"Category\" options."); document.ccpay.card.focus(); return false; } if (document.ccpay.expmonth.selectedIndex <= 0){ alert("Please select the card expiration month."); document.ccpay.expmonth.focus(); return false; } if (document.ccpay.expyr.selectedIndex <= 0){ alert("Please select the card expiration year."); document.ccpay.expyr.focus(); return false; } return true; } //--> </script> </head> <body> <form id="ccpay" name"ccpay" method="POST" action="paydll.asp" onsubmit="return verifyform();"> <p align="center"><font face="Verdana" size="4" color="#800000"><b>Credit Card Payment Information</b></font></p> <div align="center"> <center> <table border="0" cellspacing="4" cellpadding="0"> <tr> <td><font face="Verdana" size="2">First Name</font></td> <td><input type="text" name="fname" size="20"></td> </tr> <tr> <td><font face="Verdana" size="2">Last Name</font></td> <td><input type="text" name="lname" size="20"></td> </tr> <tr> <td><font face="Verdana" size="2">Address 1</font></td> <td><input type="text" name="add1" size="20"></td> </tr> <tr> <td><font face="Verdana" size="2">Address 2</font></td> <td><input type="text" name="add2" size="20"></td> </tr> <tr> <td><font face="Verdana" size="2">City</font></td> <td><input type="text" name="city" size="20"></td> </tr> <tr> <td><font face="Verdana" size="2">State</font></td> <td><input type="text" name="state" size="2"></td> </tr> <tr> <td><font face="Verdana" size="2">Zip</font></td> <td><input type="text" name="zip" size="10"></td> </tr> <tr> <td><font face="Verdana" size="2">Card</font></td> <td><font face="Verdana" size="2"><input type="radio" value="mc" name="card">MC <input type="radio" value="visa" name="card">Visa <input type="radio" value="amex" name="card">Amex <input type="radio" value="disc" name="card">Discover</font></td> </tr> <tr> <td><font face="Verdana" size="2">CC Number</font></td> <td><input type="text" name="ccnum" size="20"></td> </tr> <tr> <td><font face="Verdana" size="2">Exp Month</font></td> <td><select size="1" name="expmonth"> </select></td> </tr> <tr> <td><font face="Verdana" size="2">Exp Year</font></td> <td><select size="1" name="expyr"> </select></td> </tr> <tr> <td><font face="Verdana" size="2">CCV</font></td> <td><input type="text" name="ccv" size="3"></td> </tr> <tr> <td colspan="2" align="center"><input type="submit" value="Go" name="B1"></td> </tr> </table> </center> </div> <p align="center"> </p> </form> <p> </p> </body> </html> Code (javascript):
Hi mopacfan A few tweaks should do it. function verifyform(){ if (document[B][COLOR=red].all[/COLOR][/B].ccpay.fname.value.length <= 0){ alert("Please enter the first name.\n"); document[B][COLOR=red].all[/COLOR][/B].ccpay.fname.focus(); return false; } [B][COLOR=red]else[/COLOR][/B] if (document[B][COLOR=red].all[/COLOR][/B].ccpay.lname.value.length <= 0){ alert("Please enter the last name.\n"); document[B][COLOR=red].all[/COLOR][/B].ccpay.lname.focus(); return false; } [B][COLOR=red]else[/COLOR][/B] if (document[B][COLOR=red].all[/COLOR][/B].ccpay.add1.value.length <= 0){ alert("Please enter the address.\n"); document[COLOR=red][B].all[/B][/COLOR].ccpay.add1.focus(); return false; } [COLOR=red]repeat for other statements[/COLOR] Code (javascript):
think the document.all only works with IE. Try replacing all references to document.ccpay with document.forms['ccpay'] hth, tom
It's actually supported by later mozilla browsers (Firefox) but you're right it shouldn't be used. You can also use: document.forms.ccpay better still: var myForm = document.getElementByID('ccpay'); if (myForm.fname.value.length <= 0){ alert("Please enter the first name.\n"); myForm.fname.focus(); etc. Code (javascript):