Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Multiple selection boxes validated

    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:

    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;
    }
    </script>
    I'm pretty new at scripting so please be gentle. This code doesn't work right now.
    "It is impossible for a man to learn what he thinks he already knows." ~ Epictetus

  • #2
    Regular Coder BonRouge's Avatar
    Join Date
    Mar 2006
    Location
    Sendai, Japan
    Posts
    328
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you post a link to your page?

  • #3
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    "It is impossible for a man to learn what he thinks he already knows." ~ Epictetus

  • #4
    Regular Coder BonRouge's Avatar
    Join Date
    Mar 2006
    Location
    Sendai, Japan
    Posts
    328
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In your 'if' bit, you have 'K501Color', but the select box is 'K501color' (small 'c').

  • #5
    New to the CF scene
    Join Date
    Oct 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, I changed it. I get the error that my 'return' statement is outside of function.

    Code:
    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;
    	else
    	//do nothing
    }
    "It is impossible for a man to learn what he thinks he already knows." ~ Epictetus

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    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.

  • #7
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it is complex really


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •