471,887 Members | 747 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,887 software developers and data experts.

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 1801
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

reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

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.