Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2005
    Thanked 0 Times in 0 Posts

    Finish code: validate form

    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?

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Near Chicago, IL, USA
    Thanked 32 Times in 31 Posts
    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" ...>

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit


    Posting Permissions

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