469,272 Members | 1,627 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Getting option values as array

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
Oct 3 '08 #1
1 1769
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[i].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[i].value);

and then ?

--
sm
Oct 3 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.