Gregor Kofler a écrit :
Laser Lips meinte:
>Hi, I have a select box and I'd like to open it from JavaScript. Is
this possible?
No.
select box == <input type="select"?
open == choice an item of the list (show an option) ?
if yes :
document.myForm.mySelect.selectedIndex = 2;
JS :
====
function showOption(item) {
var s = document.myForm.mySelect, o = s.options;
for(var i=0, n=o.length; i<n; i++)
if(o[i].text == item) {
s.selectedIndex = i;
break;
}
}
function launchOption(item) {
var s = document.myForm.mySelect, o = s.options;
for(var i=0, n=o.length; i<n; i++)
if(o[i].text == item) {
location = o[i].value;
break;
}
}
HTML :
======
<form name="myForm">
<select name="mySelect">
<option value="http://www.google.com/">Google</option>
<option value="http://www.yahoo.com/">Yahoo!</option>
<option value="http://en.wikipedia.org/">Wiki</option>
</select>
</form>
<button onclick="showOption('Yahoo!')">Show Yahoo!</button>
<button onclick="launchOption('Wiki')">Go to Wikipedia</button>
--
sm