How to get value(s) from Multiple Selection enabled Select Box

R

Raghuram Banda

Hi All,

I'm on a task some thing like getting selected value(s) from source
SELECT box and appending these value(s) to destination SELECT box. Can
anyone help me how to get multiple values from SELECT box using
JavaScript (DOM).

Thanks in advance.
 
L

Lasse Reichstein Nielsen

Raghuram Banda said:
I'm on a task some thing like getting selected value(s) from source
SELECT box and appending these value(s) to destination SELECT box. Can
anyone help me how to get multiple values from SELECT box using
JavaScript (DOM).

If the select element is "selRef", we can iterate through the selected
options as:

for (var i=selRef.options.length-1; i >= 0;i++) {
if (selRef.options.checked) {
// do something
}
}

I count backwards, so if you remove the option you are looking at,
it will not affect the ones you haven't visited yet.

/L
 
L

Lasse Reichstein Nielsen

Lasse Reichstein Nielsen said:
for (var i=selRef.options.length-1; i >= 0;i++) {
Doh, that should ofcourse be i--
if (selRef.options.checked) {


And this should be
if (selRef.options.selected) {


I hate it when I reflexively press submit before testing.
/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,444
Messages
2,571,709
Members
48,796
Latest member
Greg L.
Top