0

ok. I have a dropdown. well call it dropdownA. I have several arrays already fashioned, that i want to loop through, and put each individual value out onto the page into it's own input field, based on the selection in the dropdown. I know how to put together the loop to get the values out onto the page. anyway, here is the meta code.

meta1array=new Array('','','','','','');
meta2array=new Array('','','','','','');
meta3array=new Array('','','','','','');

function metacode(id){
    {
var a=get.the.dd.selIndex;
var b=get.the.dd.options[a].value; //comes back as 'meta1'. other opts are meta2, meta3
var c=b+'array';

for(i=0;i<c.count;i++)
 {
  loop here to popout values
  }
}

i have looked everywhere, and i haven't come up with anything. I also admit that my brain is starting to mushify from a few weeks straight of coding, and this is the first time i have come across this. so, please. i would be greatful for any help.

5
  • Your question doesn't make much sense to me. Are you struggling with getting the value of the selected option, or how to use it to get values from the arrays? Commented Aug 23, 2011 at 3:18
  • what i am trying to do is use the value of variable b, which is "meta", and add it to the word "array", to make variable c="metaarray" so that the c becomes metaarray itself. Commented Aug 23, 2011 at 3:21
  • 2
    please don't ever pseudo-code again Commented Aug 23, 2011 at 3:28
  • Ok, you are trying to concatenate a string to use as a variable name. Answers below. Commented Aug 23, 2011 at 3:28
  • use jsfiddle.net, it might save some time Commented Aug 23, 2011 at 3:29

2 Answers 2

1

Global variables are members of the window object.

var c = window[b + 'array'];

It might be wise to make your arrays members of some other object though, for tighter scoping (avoid cluttering the global namespace).

Sign up to request clarification or add additional context in comments.

Comments

0
metaobject = {
               meta1array: ['','','','',''], 
               meta2array: ['','','','',''], 
               meta3array: ['','','','','']
             };

// snip

var arr = metaobject[b + 'array'];
for(var i=0;i<arr.length;i++) {
    //do work
}

Check out the fiddle using jquery here.

1 Comment

ty very much. this is uber. also to the guy above who seemed to be on the right track =d

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.