471,887 Members | 750 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

Select/Unselect items in multiple select using javascript

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
1 9704
608 512MB
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.

Similar topics

4 posts views Thread by headware | last post: by
1 post views Thread by mike robinson | last post: by
6 posts views Thread by Ben Hallert | last post: by
2 posts views Thread by Chris Plowman | last post: by
1 post views Thread by sab | last post: by
4 posts views Thread by Matt Ratliff | last post: by
2 posts views Thread by Andy Baker | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.