View Full Version : Finish code: validate form

Local Hero
07-05-2005, 09:41 PM
I have 3 dropdown selection boxes. I want to make sure that each of them are chosen before submission.

<form name="form_1" action="http://www.localheroclothing.com/store/customer/cart.php" >
<select name="select_1">
<option>-- Products --</option>
<option value=1>T-Shirt</option>
<option value=2>Longsleeve T-Shirt</option>
<select name="select_2">
<option>Please Select a Color</option>
<option>red </option>
<option>green </option>
<select name="select_X">
<option>Please Select a Size</option>
</select><INPUT name="submit" type="button" onClick="box();" value="Add to Cart" >
When the user submits, it check with the box() function:

function box() {
if (window.document.form_1.select_2.selectedIndex == 0 || window.document.form_1.select_X.selectedIndex == 0)
alert("Where do you think you're going?");
} else {
This is where I get my problem. If you don't select an option, the alert pops up and says "where are you going?" -Good- But when everything is filled out the for won't submit -Bad- What needs to be in the box() function to make the form submit?

07-05-2005, 09:50 PM
Does an error show up?
What do you mean by "won't submit"? Nothing happens, or you get an error?

Also, you don't have a method here. Most PHP scripts specifically check for POST vars. Yet this will submit with GET since you didn't say otherwise.
<form method="POST" ...>