How do I deselect the selected value from a dropdown list using Prototype.
From
<select id=“mylist” MULTIPLE >
<option value=“val-1”>Value 1</option>
<option value=“val-2” SELECTED>Value 2</option>
<option value=“val-3”>Value 3</option>
</select>
To
<select id=“mylist” MULTIPLE >
<option value=“val-1”>Value 1</option>
<option value=“val-2”>Value 2</option>
<option value=“val-3”>Value 3</option>
</select>
Thanks for any help in advance.
I'm not sure how to do it in prototype, but I can do it in JavaScript.
For a regular select, set yourSelectElement.selectedIndex = -1
.
For a multiple select, you can just ctrl+click on the selected item, but you can do it programmatically as well. See link.
http://jsfiddle.net/kaleb/WxJ9R/
You can't : you'll have to add an empty option
<option></option>
and then
$$("#mylist option[selected]")[0].selected = false;
$$("#mylist option")[0].selected = true;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With