Can anyone tell me why the selectedLength function is failing in the code below?
It can be played with here: http://jsbin.com/oluyu6/3/edit
Thanks.
Svend
It can be played with here: http://jsbin.com/oluyu6/3/edit
Thanks.
Svend
Code:
<!DOCTYPE html> <html> <head> <script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <meta charset=utf-8 /> <title>JS Bin</title> <style type="text/css"> <!-- option.emphasised { background-color: white; color: blue; font-style: oblique; } --> </style> <script> function selectedLength(box) { selected = []; for(var i=0; i< box.options.length;i++) { if(box.options[i].selected) selected.push( box.options[i].value); } return selected.length; } function toggleArrowBySelectedVal(option_array, list, arrow) { if ( (selectedLength(list)==1) && (option_array.find(Number(list.value)))) arrow.disabled=false; else arrow.disabled=true; } window.onload = (function(){ $("#first").change(function() { toggleArrowBySelectedVal([8,15],$("#first"),$("#expandPlus1PDC"));}); }) </script> <!--[if IE]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <style> article, aside, figure, footer, header, hgroup, menu, nav, section { display: block; } </style> </head> <body> <p id="hello">Hello World</p> <SELECT NAME="first" SIZE=13 multiple id="first" selectedIndex=-1> <option value="1" class="">A</option> <option value="2" class="">B</option> <option value="8" class="emphasized">C</option> <option value="15" class="emphasized">D</option> <option value="10" class="">E</option> </select> <input name="expandPlus1PDC" type="button" disabled id="expandPlus1PDC" title="Expand list" value=">>"> </body> </html>
Comment