Getting option values as array

L

laredotornado

Hi,

I have a select menu on my page. What is the easiest way to get the
VALUE attribute of each of the options starting from index 1 and put
all those into their own array? If iterating over the options array
using a for loop is the answer, that's fine, I just thought there may
be some function out there I hadn't thought of.

Thanks, - Dave
 
S

SAM

Le 10/3/08 6:35 PM, laredotornado a écrit :
Hi,

I have a select menu on my page. What is the easiest way to get the
VALUE attribute of each of the options starting from index 1 and put
all those into their own array? If iterating over the options array
using a for loop is the answer, that's fine, I just thought there may
be some function out there I hadn't thought of.

Why do you need your options in an array ?
They already are a collection, what would you get more if they become an
array?

var o = document.forms[0].mySelect.options;
for(var i=1; i<o.length; i++;)
if(o.value == 'something') alert('found');


anyway to xfer the collection in an array that's done very easily :

var n = []
var o = document.forms[0].mySelect.options;
for(var i=1; i<o.length; i++;) n.push(o.value);

and then ?
 

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

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,250
Latest member
Charlesreero

Latest Threads

Top