473,503 Members | 1,849 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Select/Unselect items in multiple select using javascript

1 New Member
Hi all,

I have a HTML multiple select (ListBox) control:

[HTML]<select id="mySelect" multiple>
<option>Apple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Banana</option>
</select>[/HTML]

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,
Michael.
Jul 29 '08 #1
1 9895
RamananKalirajan
608 Contributor
Hi Michael, I hope this code will help you out

[HTML]<html>
<head>
<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)
{
alert(document.getElementById('mySelect').options[i].text);
}
}
}
</script>
</head>
<body><form>
<select name="mySelect" size="10" multiple>
<option>Apple</option>
<option>Pear</option>
<option>Pea</option>
<option>Banana</option>
<option>Orange</option>
<option>Mango</option>
<option>Lime</option>
<option>Goa</option>
<option>Dates</option>
</select>
<input type="button" onclick="selectMultiple()"
value="Select multiple">
</form></body>
</html> [/HTML]

Regards
Ramanan Kalirajan
Jul 29 '08 #2

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

Similar topics

2
3809
by: Andrea | last post by:
Hi, I'm trying to emulate part of our client-server application as a web site so customers can use it, and I'm stuck when it comes to re-ordering items in a list. Basically we have a list of...
4
11249
by: headware | last post by:
I have a <select> control that contains many entries. It allows the user to multi-select a group of them, click a button, and store the selected data in a database. Normally they do this starting...
1
2830
by: mike robinson | last post by:
here's my code: <script type="text/javascript"> function checkUncheckAll(t, type) { for(i=1; i<t.length; i++) { if (t.name == "hosting" && type == "hosting") t.checked=t.checked; if (t.name...
6
4268
by: Ben Hallert | last post by:
Hi guys, I'm trying to figure out what bone headed mistake I made on something I put together. I've got a form (named 'context') that has a variable number of select-multiple inputs on it. ...
2
9905
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
1
2216
by: sab | last post by:
Hi, We have a web form with a listbox. The listbox is a multiple select listbox and has data that looks something like: ALL Unit 1 Unit 2 Unit 3 Note: "ALL" is always the first item in...
4
2441
by: Matt Ratliff | last post by:
Hello, I would appreciate any assistance you have with the following problem: I have (as an example) an array of values as follows: arrayvalues=new Array("0001","0003","0005") where each is the...
2
6786
by: Andy Baker | last post by:
I have a VB.NET 2003 application that uses several datagrids. The behaviour I want from the datagrid is to select (highlight) the entire row when I click on any cell in a row. I have done this...
25
5364
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section. ...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7006
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5021
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4685
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1519
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
397
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.