Turn drop-down list into list box

Subscribe to Turn drop-down list into list box 6 posts, 3 voices

 
Arithmomaniac User

Can someone write a script to turn a drop-down list
http://en.wikipedia.org/wiki/Drop-down_list
into a list box
http://en.wikipedia.org/wiki/List_box
with a toggle to either
only show x at a time before scrolling, or
show all of them?

Thanks,
Arithmomaniac

 
Aquilax Scriptwright

You want to turn every drop down in a list box?


Array.forEach(document.getElementsByTagName("select"),function(select){select.size=select.options.length;});

 
jerone Scriptwright

Nice clean code, Aquilax.

 
Arithmomaniac User

Beautiful! Thanks a ton.
Can you rewrite the code so that the size of the box can be inputted as a user script command (ie if I put in 6 with a 10-entry list, it will scroll; 0 would mean "all")?

Thanks,
Arithmomaniac

 
Aquilax Scriptwright

Try with this, it's written on the fly ...


GM_registerMenuCommand("Resize Selects",function(){resizeSelects(prompt("New selects size:"));});

function resizeSelects(size){window.selectsSize=size;Array.forEach(document.getElementsByTagName("select"),function(select){select.size=selectsSize!="0"?selectsSize:select.options.length;});}

 
Arithmomaniac User

Wow! That works great, too.
Two theoretical improvements that could be made (but don't have to be):

1) Clicking is not automatic selection; double-clicking or click-Enter is.
2) Selecting multiple items works (after the first item, the things open in new tabs).

Thanks,
Arithmomaniac