469,271 Members | 1,433 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

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 9335
607 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 suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.