[Javascript] Fields required

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mike1961
    New Member
    • Apr 2008
    • 66

    [Javascript] Fields required

    Hi all.

    I have this web page:

    Code:
    <html>
    
    <head>
    
    </head>
    
    <body>
    
    <form method="POST" action="go.asp">
    
    <select size="1" name="A">
    <option>Select</option>
    <option value="POSITIVE">POSITIVE</option>
    <option value="NEGATIVE">NEGATIVE</option>
    </select>
    
    <select size="1" name="B">
    <option>Select</option>
    <option value="0">Open</option>
    <option value="1">Close</option>
    </select>
    
    <input type="submit" value="GO" name="B1">
    
    </form>
    </body>
    
    </html>
    If select value positive or negative in the select "A", in the select "B" required value 1, would say "Close".

    If select value 2 would say "Open" in the select "B" stop the form, its possible?

    Can you help me ?
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    hi ...

    i'm a little bit confused ... could you try to explain it a bit better? what should happen when you select an option in the first select-box and what should happen in case of a selection in the second one? i cannot see any value="2"?

    kind regards

    Comment

    • Mike1961
      New Member
      • Apr 2008
      • 66

      #3
      Originally posted by gits
      hi ...

      i'm a little bit confused ... could you try to explain it a bit better? what should happen when you select an option in the first select-box and what should happen in case of a selection in the second one? i cannot see any value="2"?

      kind regards
      Sorry Gits... I wrong...

      If select value positive or negative in the select "A", in the select "B" required value 1, would say "Close".

      If select value 0 would say "Open" in the select "B" stop the form.

      For example:

      Select A ===> POSITIVE or NEGATIVE value
      Select B ===> CLOSE ( value=1 ) ===> it's right

      Select A ===> POSITIVE or NEGATIVE
      Select B ===> OPEN ( value = 0 ) ===> it's wrong and the stop the form


      You understand?

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        so the select A is irrelevant and you just need to check the selected value of select-node B ... :) check it when clicking the submit-button or onsubmit of the form

        kind regards

        Comment

        • Mike1961
          New Member
          • Apr 2008
          • 66

          #5
          Originally posted by gits
          so the select A is irrelevant and you just need to check the selected value of select-node B ... :) check it when clicking the submit-button or onsubmit of the form

          kind regards

          I do not understand.... :(

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5388

            #6
            as you see ... the only thing that has to be checked is the value of select-node B ... since you said that pos or! neg could have been selected in A in any case, while the form shouldn't be submitted when node B has a value of 0. just give your node an ID and call a function onsubmit of the form ... here is an example:

            [CODE=javascript]function chk_form() {
            var n = document.getEle mentById('my_id _for_B');

            return (n.value == 1);
            }[/CODE]
            and in you html code you should have:

            [HTML]<form method="POST" action="go.asp" onsubmit="retur n chk_form();">
            [/HTML]
            and even the ID:

            [HTML]<select size="1" id="my_id_for_B " name="B">
            [/HTML]
            kind regards

            Comment

            • Mike1961
              New Member
              • Apr 2008
              • 66

              #7
              Many thanks...
              kind regards

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5388

                #8
                no problem ;) ... post back to the forum anytime you have more questions ...

                kind regards

                Comment

                Working...