daredevil88 Posted April 25, 2007 Share Posted April 25, 2007 hi, I have created an a form with image submission button. how can I validate input field is empty or not? here is the example of what I did <html> <body> <form method="post" name="purchase_form" action = "order.php" onsubmit="return validate_form(this)"> <table> <tr><th colspan = 2 bgcolor=#C6EFFY align = 'left'>Please enter your delivery details</th></tr> <tr><td width=100> <td><td> </td></tr> <tr><td><b>First Name: </b></td> <td><input type = 'text' name = 'firstname' maxlength = 30 size = 30></td></tr> <tr><td><b>Last Name: </b></td> <td><input type = 'text' name = 'lastname' maxlength = 30 size = 30></td></tr> <td><input type="image" src="images/purchase.jpg" width="135" height="40" name="Purchase"></td> </table> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
fenway Posted April 25, 2007 Share Posted April 25, 2007 And where is that function? Quote Link to comment Share on other sites More sharing options...
daredevil88 Posted April 25, 2007 Author Share Posted April 25, 2007 sorry, the function is here. I take this example from one of the forums but how can I add to validate more than one field to fit into this function? <script type="text/javascript"> function validate_required(field,alerttxt) { with (field) { if (value==null||value=="") {alert(alerttxt);return false} else {return true} } } function validate_form(thisform) { with (thisform) { if (validate_required(firstname,"First Name must be filled out!")==false) {fristname.focus();return false} } with (thisform) { if (validate_required(lname,"Last Name must be filled out!")==false) {lastname.focus();return false} } } </script> Quote Link to comment Share on other sites More sharing options...
fenway Posted April 26, 2007 Share Posted April 26, 2007 What at ugly looking function... with() should never be used in the real world. But even so, you should be able to "use" the same function for the image, because it too has a .value.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.