0

I am trying to use a drop down box to update some data. what I would like to do is use a function to return the variable ds,ds1 depending on what the user selects. For example. if they select ds from the dropdown box I want the function to return the actual var ds and not the ds value, since I want to reference the variable ds in another bit of code depending on the selection. Hope this makes sense.

Thanks for your help,

<div >
        <select id="dropdown" onchange="updateData()">
            <option value="ds">ds</option>
            <option value="ds1">ds1</option>

        </select>
    </div>    


 var ds = [[{x:0,y:72}],[{x:0,y:28}]];

 var ds1 = [[{x:0,y:2}],[{x:0,y:50}]];

  function myVar() {
  return (dropdown.value);} //I want this to be the variable ds i.e. var ds //[[{x:0,y:72}], [{x:0,y:28}]]; not the value. 
Lars Kotthoff
  • 107,425
  • 16
  • 204
  • 204
user2259146
  • 259
  • 2
  • 5
  • 15
  • once you learn how to use JS to get something from a form, then it'd simply `return array_that_has_your_values[value_from_form_used_as_key]`... – Marc B Jun 13 '14 at 21:43
  • Ok I solved this using the eval command which can be used to convert the string value and reference it to the variable. I replaced the dropdown.value with (eval("("+dropdown.value+")")); Code is much smaller now. – user2259146 Jun 14 '14 at 08:03

1 Answers1

0
var arr = {};
arr["ds"] = [[{x:0,y:72}],[{x:0,y:28}]];
arr["ds1"] = [[{x:0,y:2}],[{x:0,y:50}]];

function myVar() {
  return (arr["dropdown.value"]);
}
Issam Zoli
  • 2,724
  • 1
  • 21
  • 35