> I don;t mean that.
> I have a select box with size of 5 and 10 options.
> Using a function i move options up and down.
> When moving tha last visible option i see it only if i scroll down.
>
> I want to do that scrolling with some code
>
> -----Original Message-----
> From: Zay Perez [mailto:zay_perez@h...]
> Sent: Monday, January 21, 2002 5:33 PM
> To: javascript
> Subject: [javascript] Re: select box
>
ok i get it. as it happens, i've had the same problem before. try these
move up and down functions i've been using. through this, i'm able to
directly manipulate and treat the listboxes as arrays. given that you have
a listbox named mylistbox:
function btnUp_onclick() {
var strStoreValue;
if ((mylistbox.selectedIndex == -1) || (mylistbox.selectedIndex == 0))
return;
strStoreValue = mylistbox.options[mylistbox.selectedIndex - 1].text;
mylistbox.options[mylistbox.selectedIndex - 1].text = mylistbox.options
[mylistbox.selectedIndex].text;
mylistbox.options[mylistbox.selectedIndex].text = strStoreValue;
mylistbox.selectedIndex = mylistbox.selectedIndex - 1;
}
function btnDown_onclick() {
var strStoreValue;
if ((mylistbox.selectedIndex == -1) || (mylistbox.selectedIndex ==
mylistbox.options.length - 1)) return;
strStoreValue = mylistbox.options[mylistbox.selectedIndex + 1].text;
mylistbox.options[mylistbox.selectedIndex + 1].text = mylistbox.options
[mylistbox.selectedIndex].text;
mylistbox.options[mylistbox.selectedIndex].text = strStoreValue;
mylistbox.selectedIndex = mylistbox.selectedIndex + 1;
}
the last lines of both functions:
up --> mylistbox.selectedIndex = mylistbox.selectedIndex - 1;
down --> mylistbox.selectedIndex = mylistbox.selectedIndex + 1;
with the use of the selectedIndex property of the select tag, sets the
focus to the item moved in the listbox so you won't have to scroll up or
down to see where the moved item is.
hope this helps =)