View Full Version : Multiple selection boxes validated

05-14-2007, 08:37 PM
Hello all! I have an order form with multiple selection boxes. I need the JavaScript to check if one selection has been selected but not another. For example, I have several t-shirts on the page. If a user wants to order a t-shirt, they need to select the color, quantity and size from three different selection boxes. Some of the users are selecting from one or two of the selection boxes but forgetting to select from the other.

Here is what I have for my code:

<script type="text/javascript">
if(document.OrderForm.tshirtname.selectedIndex != 0 || document.OrderForm.tshirtname.selectedIndex != 0 || document.OrderForm.tshirtname.selectedIndex != 0){
//tshirtname is incomplete
alert("You're selection for tshirtname is incomplete. Please ensure that you have entered a color, size, and quantity.");
return false;

I'm pretty new at scripting so please be gentle. This code doesn't work right now.

05-14-2007, 08:39 PM
Can you post a link to your page?

05-14-2007, 08:47 PM

05-15-2007, 02:17 AM
In your 'if' bit, you have 'K501Color', but the select box is 'K501color' (small 'c').

05-16-2007, 09:23 PM
Thanks, I changed it. I get the error that my 'return' statement is outside of function.

if(document.OrderForm.K501color.selectedIndex != 0 || document.OrderForm.K501Qty.selectedIndex != 0 || document.OrderForm.K501Size.selectedIndex != 0){
//K501 is incomplete
alert("You're selection for K501 is incomplete. Please ensure that you have entered a color, size, quantity.")
return false;
//do nothing

05-16-2007, 09:33 PM
You can't do a return outside of the function. When do you want this validation to happen? This should be inside a function and called on some event like form onsubmit.

05-17-2007, 02:22 PM
it is complex really