Reputation: 2752
I am populating the options in dropdown list using mySQL output. These output values are ranked and I want to keep only top 20 values out of 100 in it. Most of the users are interested in only one of these top 20 items. Occasionally a user may want to look something which is low ranked (21st, 22nd ... item).
I remember that I saw this in some website where if the desired option is not present, an option was there "not in the list". Selecting this option creates an input box where a user can write their value.
How this functionality can be acheived? Suggestion of any article pointing to similar problem will be highly appreciated.
Upvotes: 0
Views: 65
Reputation: 104795
Using javascript you can do this fairly easily. Since no HTML was provided, I made a sample:
HTML:
<select id="test">
<option value="0">Sample</option>
<option value="other">Other</option>
</select>
<input type="text" id="test2" style="display:none;"/>
JS:
document.getElementById("test").onchange = function() {
var textbox = document.getElementById("test2");
if (this.value == "other") {
textbox.style.display = "block";
} else {
textbox.style.display = "none";
}
}
Demo: http://jsfiddle.net/DtRhk/
Upvotes: 1