| | |
Multiple select autoscroll to last item
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
Hi, I've been busy with many things that have been keeping me away from the computer the last several weeks ... sorry for the lag time in getting back to this.
It's actually pretty easy to modify this script to act on specific form-element fields instead of on the forms.
Try this:
It's actually pretty easy to modify this script to act on specific form-element fields instead of on the forms.
Try this:
javascript Syntax (Toggle Plain Text)
<html> <head> <script type="text/javascript"> window.onload = function () { // Since we only need to auto-scroll the select elements // after the page has loaded ... // list auto-scroll selects by id select_list = new Array( 'test_one', 'test_too' ); scroll_selected( select_list ); }; function scroll_selected ( selects ) { OUTER: for ( var i = 0; i < selects.length; i ++ ) { var select = document.getElementById(selects[i]); var opts = select.getElementsByTagName('option'); for ( var j = opts.length -1; j > 0; --j ) { if ( opts.item(j).selected == true ) { select.scrollTop = j * opts.item(j).offsetHeight; opts.item(j).selected = true; continue OUTER; } } } } </script> </head> <body style="padding:60px"> <form> <p>Select Multiple:<br /> <select id="test_one" multiple size="3"> <option name="one" value="1">one</option> <option name="two" value="2">two</option> <option name="three" value="3" selected>three</option> <option name="four" value="4">four</option> <option name="five" value="5">five</option> <option name="six" value="6" selected>six</option> </select> <p>Select One:<br /> <select size="3"> <option name="one" value="1" selected>one</option> <option name="two" value="2">two</option> <option name="three" value="3">three</option> <option name="four" value="4">four</option> <option name="five" value="5">five</option> <option name="six" value="6">six</option> </select> <p>Select Multiple:<br /> <select id="test_too" multiple size="3"> <option name="one" value="1">one</option> <option name="two" value="2">two</option> <option name="three" value="3" selected>three</option> <option name="four" value="4" selected>four</option> <option name="five" value="5">five</option> <option name="six" value="6">six</option> </select> <p> <input type="submit" /> </form> </body> </html>
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
![]() |
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: how to maximize table cell height
- Next Thread: FCKeditor chracter counter Problem at client side.
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array automatically beta box browser captchaformproblem cart child class close codes column css date debugger decimal dependent design disablefirebug dom download editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe index java javascript javascripthelp2020 jquery jsf jsp jump libcurl listbox maps masterpage math media menu microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php player position post problem programming prototype redirect safari scale scriptlets scroll search security select software toggle unicode w3c web window windowofwords \n





