[Urgently] Form Validation If & then!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • closser
    New Member
    • Nov 2012
    • 7

    [Urgently] Form Validation If & then!

    Hi guys, first i hope u will understand me...
    So i want to make a javascript to be shown if somebody chooses option A to show the javascripts for the A1,A2,A3 and if they choose B to show javascripts for the B1,B2,B3. So the A and B it will firstly asked as options from a <select> tag
    eg.
    Code:
    <select name="AorB" >
    <option value="" selected="selected">Select...</option>
    <option value="A" >Option A</option>
    <option value="B" >Option B</option>
    </select>
    I'm already using this way of javascript (Error Alerts):

    Code:
    <SCRIPT language=JavaScript>
    <!--
    function check(form) {
    if (form.Password.value == "")
    { alert("Please enter your Password."); form.Password.focus(); return;}
    if (form.Password.value.length < 8)
    { alert("Please enter a valid Password."); form.Password.focus(); return;}
    form.submit()
    }
    //-->
    </SCRIPT>
  • closser
    New Member
    • Nov 2012
    • 7

    #2
    P.S: I don't want to make complications when they choose A to get B option javascripts.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      I'm not sure what you mean. Do you mean you want to populate a different drop down list with those values depending on what is selected? You can use the onchange event to call a javascript function that will add those options to the other drop down list. If you mean something else, then I don't understand what it is that you're looking for.

      Comment

      • closser
        New Member
        • Nov 2012
        • 7

        #4
        Hi Rabbit, thank for your reply, i mean if We select OPTION A there will be shown some Input-s ....and javascript will ask only for the shown input-s so it means OPTION A input-s ... but not to ask for OPTION B input-s too even that they're not shown cause we didnt select OPTION B ... i hope i explained a little for you.

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          I still don't understand. What you said is very similar to your original post. Try explaining it a different way. Alternatively, do a mockup and post the image of what you're trying to achieve.

          Comment

          • closser
            New Member
            • Nov 2012
            • 7

            #6
            i'm so sorry for ur time, please listen... i will try to explain .... i want the javascript to be shown if we don't fill input-s on the form , so the first INPUT (selcet tag) is the main one that includes Option A and Option B, like this:

            Code:
            <select name="AorB" >
            <option value="" selected="selected">Select...</option>
            <option value="A" >Option A</option>
            <option value="B" >Option B</option>
            </select>
            Then, once we choose Option B there down will be shown few more input-s (like i said above: B1,B2,B3) , and i want same thing to happen if we choose Option A, so it will show DIFFERENT input-s (A1,A2,A3) , so essence is that i want this javascript to ask for input-s that are shown after choosing an option A or B , but not ask for ALL input-s , only the once that will be shown after selecting an option.

            Comment

            • Rabbit
              Recognized Expert MVP
              • Jan 2007
              • 12517

              #7
              By inputs, do you mean actual form elements? <input>? If so, use the on change event to update the visibility property.

              Comment

              • closser
                New Member
                • Nov 2012
                • 7

                #8
                Yea i meant <input>-s, how do i use the on change event please ?

                I'm currently using this way:

                Code:
                <SCRIPT language=JavaScript>
                <!--
                function check(form) {
                if (form.Password.value == "")
                { alert("Please enter your Password."); form.Password.focus(); return;}
                if (form.Password.value.length < 8)
                { alert("Please enter a valid Password."); form.Password.focus(); return;}
                form.submit()
                }
                //-->
                </SCRIPT>

                Comment

                • closser
                  New Member
                  • Nov 2012
                  • 7

                  #9
                  Please check out this LINK, use view-source too , to understand it..thank you so much once again.

                  Comment

                  • Rabbit
                    Recognized Expert MVP
                    • Jan 2007
                    • 12517

                    #10
                    This is how you use the on change event.
                    Code:
                    <select name="someName" onchange="someFunction()">
                    Then you just need to write whatever function you need. In this case, you will write one to change the visibility of the <input>s you want to show depending on what they've chosen.

                    Comment

                    • closser
                      New Member
                      • Nov 2012
                      • 7

                      #11
                      i fixed it already, thank you so much Rabbit sir, honestly. Cheers.

                      Comment

                      Working...