By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,793 Members | 1,257 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,793 IT Pros & Developers. It's quick & easy.

Getting option values as array

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.