Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <select id="mylist"><option>Test</option>
- <option>Test</option>
- <option>Test</option>
- <option>Test</option>
- </select>
- Event.observe('mylist', 'change', checkList);
- function checkList(e)
- {
- var count = 0;
- var listObj = this;
- // Count selected items
- for (i=0; i < listObj.options.length; i++) {
- if (listObj.options[i].selected) {
- count++;
- }
- }
- // If the count is over, tell me the last selected item
- if (count > 10) {
- var e = e || window.event;
- var tgt = e.target || e.srcElement;
- alert(tgt.nodeName + ' Index:' + tgt.index);
- }
- }
- function checkList(e)
- {
- var count = 0;
- var listObj = this;
- // Count selected items
- for (i=0; i < listObj.options.length; i++) {
- if (listObj.options[i].selected) {
- // If the count is over, tell me the last selected item
- if (++count > 10) {
- alert('Index:' + i);
- return;
- }
- }
- }
- }
- $$('select#mylist option[selected]:last')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement