Any way to scroll listbox to pre-selected element?
Moderator: General Moderators
Any way to scroll listbox to pre-selected element?
I have a listbox auto-highlighted by a POSTed variable.
Most of the time the highlighted term is off-screen. Is there any way to get js to autoscroll to the highlighted term?
Most of the time the highlighted term is off-screen. Is there any way to get js to autoscroll to the highlighted term?
Something like this?
Code: Select all
<select name=productsї] multiple size=3 class=text>
<option value="a">All</option>
<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
<option value="4" >4</option>
<option value="5" >5</option>
<option value="6">6</option>
<option value="7" selected>7</option>
<option value="8" >8</option>
<option value="9" >9</option>
<option value="10" >10</option>
<option value="11" >11</option>
</select>
<script language=javascript>
document.list.productsї].elementї'7'].focus()=true;
</script>Apologies for the redux:
I tried this, and option '7' is highlighted, but it is still out of view.
Options 1 to 3 are displayed (size=3), and 7 is highlighted if user scrolls down.
If there are no other options, I could rearrange the array to display options 6,7,8 first, but that's a messy solution.
I tried this, and option '7' is highlighted, but it is still out of view.
Options 1 to 3 are displayed (size=3), and 7 is highlighted if user scrolls down.
Code: Select all
<form name=list>
<table>
<td>
<select name=productsї] multiple size=3 class=text>
<option value="a">All</option>
<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
<option value="4" >4</option>
<option value="5" >5</option>
<option value="6">6</option>
<option value="7" selected>7</option>
<option value="8" >8</option>
<option value="9" >9</option>
<option value="10" >10</option>
<option value="11" >11</option>
</select>
</td>
</table>
<script language=javascript>
document.formsї'list'].elementsї'productsї7]'].focus();
</script>
</form>