Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. <select id="mylist"><option>Test</option>
  2. <option>Test</option>
  3. <option>Test</option>
  4. <option>Test</option>
  5. </select>
  6.  
  7. Event.observe('mylist', 'change', checkList);
  8.  
  9. function checkList(e)
  10. {
  11. var count = 0;
  12. var listObj = this;
  13. // Count selected items
  14. for (i=0; i < listObj.options.length; i++) {
  15. if (listObj.options[i].selected) {
  16. count++;
  17. }
  18. }
  19.  
  20. // If the count is over, tell me the last selected item
  21. if (count > 10) {
  22. var e = e || window.event;
  23. var tgt = e.target || e.srcElement;
  24. alert(tgt.nodeName + ' Index:' + tgt.index);
  25. }
  26. }
  27.  
  28. function checkList(e)
  29. {
  30. var count = 0;
  31. var listObj = this;
  32. // Count selected items
  33. for (i=0; i < listObj.options.length; i++) {
  34. if (listObj.options[i].selected) {
  35. // If the count is over, tell me the last selected item
  36. if (++count > 10) {
  37. alert('Index:' + i);
  38. return;
  39. }
  40. }
  41. }
  42.  
  43. }
  44.  
  45. $$('select#mylist option[selected]:last')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement