...

View Full Version : Making a search form where inputs only appear on certain selection



Kolusion
08-22-2011, 02:39 PM
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?

webdev1958
08-22-2011, 02:45 PM
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.

VIPStephan
08-22-2011, 03:10 PM
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.

Kolusion
08-22-2011, 03:21 PM
"go on a website where such a feature exists and copy it from there"

You got a website?

Philip M
08-22-2011, 04:38 PM
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.


<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

VIPStephan
08-22-2011, 05:24 PM
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.

webdev1958
08-22-2011, 05:32 PM
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.

venegal
08-22-2011, 05:33 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum