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 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy [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 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>
    P.S: I don't want to make complications when they choose A to get B option javascripts or reverse.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Despite the similar sounding names, Java is not the same as Javascript.
    Moving from Java forum to Javascript forum.

  • #3
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok sorry Fou-Lu, ...btw i hope anybody understood ..... i meant 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.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,454
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    Well, for starters, you have to use the ONCHANGE event of the <select> to change *WHAT* is displayed. That is, to show one or the other set of questions/fields.

    Have you done that?

    You don't even show what those other questions/fields are in your post.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Well, for starters, you have to use the ONCHANGE event of the <select> to change *WHAT* is displayed. That is, to show one or the other set of questions/fields.

    Have you done that?

    You don't even show what those other questions/fields are in your post.
    Hi Old Pedant, thanks for the reply, . 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.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,454
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    Then, once we choose Option B there down will be shown few more input-s (like i said above: B1,B2,B3) ...
    Yes, I know. And I wanted you to show us how you will present B1,B2,B3 and what kind of fields they are, etc., etc.

    Don't make us create a dummy HTML page for you just to demonstrate this simple code, only to find out that our dummy HTML isn't anything like what you wanted.

    Give us the HTML with *ALL* fields (A1,A2,A3 as well as B1,B2,B3) *FIRST* and then it's easier to show you how simple the code is.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #7
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Yes, I know. And I wanted you to show us how you will present B1,B2,B3 and what kind of fields they are, etc., etc.

    Don't make us create a dummy HTML page for you just to demonstrate this simple code, only to find out that our dummy HTML isn't anything like what you wanted.

    Give us the HTML with *ALL* fields (A1,A2,A3 as well as B1,B2,B3) *FIRST* and then it's easier to show you how simple the code is.
    Hi again, idk if im allowed to send a link, but here is it: LINK

    use view-source to view what i included there, thank you so much , once again!

  • #8
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    fixed / thank you everyone!

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,454
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    Great!

    I tried to go to your link, but it just gives a message saying the index page is missing.

    If you need more help, post a corrected link. Yes, posting links that show code like that is not only permissible but encourage. You should only get dinged if it was an obvious attempt at advertising or it linked to a site that had, shall we say, improper content.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

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