By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,829 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

Select/Unselect items in multiple select using javascript

P: 1
Hi all,

I have a HTML multiple select (ListBox) control:

[HTML]<select id="mySelect" multiple>

I'm looking for a way to select / unselect a few items in this list using javascript.
I saw, that selectedItem member allows to controll such functionality, but it allows to deal with a single item only, while I need multi-selections.

Any ideas?

Thanks in advance,
Jul 29 '08 #1
Share this Question
Share on Google+
1 Reply

P: 607
Hi Michael, I hope this code will help you out

<script type="text/javascript">
function selectMultiple()
for (var i=0; i<document.getElementById('mySelect').options.leng th; i++)
if (document.getElementById('mySelect').options[i].selected == true)
<select name="mySelect" size="10" multiple>
<input type="button" onclick="selectMultiple()"
value="Select multiple">
</html> [/HTML]

Ramanan Kalirajan
Jul 29 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.