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
Reply

Join Date: Jun 2008
Posts: 55
Reputation: kvdd is an unknown quantity at this point 
Solved Threads: 2
kvdd kvdd is offline Offline
Junior Poster in Training

Re: Multiple select autoscroll to last item

 
0
  #11
Oct 2nd, 2008
Anyone has the time to look at this problem, its just not solved right now.

Thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: Multiple select autoscroll to last item

 
0
  #12
Oct 2nd, 2008
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:
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4.  
  5. window.onload = function () {
  6. // Since we only need to auto-scroll the select elements
  7. // after the page has loaded ...
  8. // list auto-scroll selects by id
  9. select_list = new Array( 'test_one', 'test_too' );
  10. scroll_selected( select_list );
  11. };
  12.  
  13. function scroll_selected ( selects ) {
  14. OUTER: for ( var i = 0; i < selects.length; i ++ ) {
  15. var select = document.getElementById(selects[i]);
  16. var opts = select.getElementsByTagName('option');
  17. for ( var j = opts.length -1; j > 0; --j ) {
  18. if ( opts.item(j).selected == true ) {
  19. select.scrollTop = j * opts.item(j).offsetHeight;
  20. opts.item(j).selected = true;
  21. continue OUTER;
  22. }
  23. }
  24. }
  25. }
  26. </script>
  27. </head>
  28. <body style="padding:60px">
  29. <form>
  30. <p>Select Multiple:<br />
  31. <select id="test_one" multiple size="3">
  32. <option name="one" value="1">one</option>
  33. <option name="two" value="2">two</option>
  34. <option name="three" value="3" selected>three</option>
  35. <option name="four" value="4">four</option>
  36. <option name="five" value="5">five</option>
  37. <option name="six" value="6" selected>six</option>
  38. </select>
  39. <p>Select One:<br />
  40. <select size="3">
  41. <option name="one" value="1" selected>one</option>
  42. <option name="two" value="2">two</option>
  43. <option name="three" value="3">three</option>
  44. <option name="four" value="4">four</option>
  45. <option name="five" value="5">five</option>
  46. <option name="six" value="6">six</option>
  47. </select>
  48. <p>Select Multiple:<br />
  49. <select id="test_too" multiple size="3">
  50. <option name="one" value="1">one</option>
  51. <option name="two" value="2">two</option>
  52. <option name="three" value="3" selected>three</option>
  53. <option name="four" value="4" selected>four</option>
  54. <option name="five" value="5">five</option>
  55. <option name="six" value="6">six</option>
  56. </select>
  57. <p>
  58. <input type="submit" />
  59. </form>
  60. </body>
  61. </html>
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 55
Reputation: kvdd is an unknown quantity at this point 
Solved Threads: 2
kvdd kvdd is offline Offline
Junior Poster in Training

Re: Multiple select autoscroll to last item

 
0
  #13
Oct 9th, 2008
Langsor, much thanks I cannot test the code now, but I test it within a week, and then I post if it is working.

Much thanks for taking time, you hear from me!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC