...

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



rishid
05-05-2006, 03:04 PM
Hi

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?

Thanks

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

Nischumacher
05-05-2006, 03: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...

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

brilliant, thanks a bunch.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum