Web Analytics Made Easy -
StatCounter Making a search form where inputs only appear on certain selection - CodingForum

Announcement

Collapse
No announcement yet.

Making a search form where inputs only appear on certain selection

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Making a search form where inputs only appear on certain selection

    I want to make a search form where inputs only appear if a certain selection has been made. For example the user selects "Green" then the input "X" appears, and if the user clicks "Black" then input "Y" appears. How can this be done? If so, can someone give me a basic example in code that I can use to copy off?

  • #2
    Originally posted by Kolusion View Post
    If so, can someone give me a basic example in code that I can use to copy off?
    yes it can be done very easily using javascript but afaik this is not a free coding service. Unless a generous person stops by, I think you'll have a better chance if you post your attempt and someone(s) can then help you with it.

    If you want someone to do it for you to then just copy, then it sounds like a homework exercise you can't do on your own.

    Comment


    • #3
      webdev1958 is right, even though he/she is very direct in expressing it. You’ll have to use JavaScript to check if a certain selection has been made and enable/show the appropirate input. But if you want something to copy then go on a website where such a feature exists and copy it from there, don’t request something here without proving any own attempt whatsoever – this is what webdev1958 was trying to point out to you. You may be lucky and someone gomes by and provides you with a hint on how to approach this.

      Now, refrain from re-posting this in the JS forum, I’m gonna move it there.
      Stop solving problems you don’t yet have!

      Comment


      • #4
        "go on a website where such a feature exists and copy it from there"

        You got a website?

        Comment


        • #5
          Originally posted by VIPStephan View Post
          to you. You may be lucky and someone gomes by and provides you with a hint on how to approach this.
          I am not sure that I like your attitude, but I will give you the benefit of the doubt. This is an adult forum for professional people, not Facebook. Please do not abuse it. One sure way to find yourself ignored here is to try being a smart-mouth.

          This is an outline example of what you are looking for. But it contains a couple of deliberate mistakes for you to fix. If you can't fix them, we will know that this was homework.

          Code:
          <form id = "mtform">
          <select id = "mysel" onchange = "show()" >
          <option value= "">Choose a color...</option>
          <option value = "Green">Green</option>
          <option value = "Black">Black</option>
          </select>
          <br><br>
          <span id = "xinp" style="display:none">X <input type = "text" id = "txt1"></span>
          <span id = "yinp" style="display:none">Y <input type = "text" id = "txt1"></span>
          </form>
          
          <script type = "text/javascript">
          function show() {
          document.getElementById("xinp").style.display="none";
          document.getElementById("yinp").style.display="none";
          var val = document.getElementById("myselt").value;
          if (val != "") {
          switch(val) {
          case "Green":document.getElementById("xinp").style.display=block; break;
          case "Black":document.getElementById("yinp").style.display=block; break;
          }
          }
          }
          
          </script>

          This year, if you want to win the Premiership, you are going to have to finish above Manchester United. - Commentator, Talksport
          Last edited by Philip M; Aug 22, 2011, 10:43 AM.

          All the code given in this post has been tested and is intended to address the question asked.
          Unless stated otherwise it is not just a demonstration.

          Comment


          • #6
            Originally posted by webdev1958
            and you still can't spell or you haven't the courage to say what you mean and instead hide behind *'s - take your pick
            Just FYI: Don’t you think you’re smarter, the OP is insulting you alright. This is just the automatic bad word filter which replaces bad words with askterisks.
            Stop solving problems you don’t yet have!

            Comment


            • #7
              I'm not sure there is a bad word detector because it didn't filter out the c word which I imagine should have been filtered out.

              Comment


              • #8
                A simple web search provides plenty of examples. You even got one in this thread (although it's true that CF is not a free coding service), and you answered that one with an insult, so I suppose you don't want the help after all.

                This thread is now locked.
                .My new Javascript tutorial site: http://reallifejs.com/
                .Latest article: Calculators — Tiny jQuery calculator, Full-fledged OOP calculator, Big number calculator
                .Latest quick-bit: Including jQuery — Environment-aware minification and CDNs with local fallback

                Comment

                Working...
                X
                😀
                🥰
                🤢
                😎
                😡
                👍
                👎