View Full Version : Help with some Js for a Select Multiple

05-05-2006, 04:04 PM

Trying to do some javascript this re/dis enables a button depending on what is selected in a multiple select box. I know selectedIndex only retusn the first value that is selected which is fine, but this keeps giving me a JS error.

This first click, gives an error but the next click it pops up an alert.

This seems like so broken.. if i mouseclick and hold and get a couple items it sometimes gives the result of the last selectionion of the box.

Whats up with this?


<select size="8" id="availableOptions" name="availableOptions" multiple style="width:150px" onclick="alert(this.options[this.selectedIndex].value)">
<option value="blah">more stuff</option>

05-05-2006, 04:17 PM
when first time the option is clicked... nothing is already selected... hence the error...
you will also notice that it alert's the previously selected option then on...

just use the onchange event insted of the onclick event...
that should be it...

05-05-2006, 04:18 PM
haha thanks just found that last onclick bug.

brilliant, thanks a bunch.