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?
Announcement
Collapse
No announcement yet.
Making a search form where inputs only appear on certain selection
Collapse
This topic is closed.
X
X
-
Originally posted by Kolusion View PostIf so, can someone give me a basic example in code that I can use to copy off?
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.
-
-
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.
Comment
-
-
Originally posted by VIPStephan View Postto you. You may be lucky and someone gomes by and provides you with a hint on how to approach this.
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, TalksportLast 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
-
-
Originally posted by webdev1958and you still can't spell or you haven't the courage to say what you mean and instead hide behind *'s - take your pick
Comment
-
-
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
-
Comment