Make my drop box hop to an option :-(
Posted: Wed Dec 01, 2004 5:29 pm
Ok, I'm making a form update dynamically and need educating 
Suppose I wanted a drop down box to automatically change it's selection depending on what a user types into a text box. The drop box hops to the option which has a value equal to the string keyed in the text box. I'm trying with no luck
Here's my attempted method....
So the form loads with the second option selected but if the user types the string "12345" in the text box I'd want to see my drop box hop to the first option.
My method doesn't seem to work. Any better ways to do this?
Thanks in advance
Suppose I wanted a drop down box to automatically change it's selection depending on what a user types into a text box. The drop box hops to the option which has a value equal to the string keyed in the text box. I'm trying with no luck
Here's my attempted method....
Code: Select all
<script language="javascript">
<!--
function updateDrop(el1,el2) {
for (i=0; i<el2.options.length; i++) {
if (el1.value == el2.optionsїi].value) {
el2.optionsїi].selected == true
}
}
}
// -->
</script>
</head>
<body>
<form action="demo" method="post" name="demo">
<input type="text" id="text1" name="text1" onKeyup="updateDrop(this,document.getElementById('drop1'))">
<br>
<select name="drop1" id="drop1">
<option value="12345">Numbers 1 to 5</option>
<option value="6789" selected>Numbers 6 to 9</option>
<option value="7529">Random 7,5,2&9</option>
</select>
</form>My method doesn't seem to work. Any better ways to do this?
Thanks in advance