Home Can't get dynamic variable name to get result on document.getElementById, only returning the string

# Can't get dynamic variable name to get result on document.getElementById, only returning the string

user4913
1#
user4913 Published in April 27, 2018, 6:42 am
 I'm new to JS and been trying for some time already to solve this myself, but after lots of searching (found lots of information on different ways to concat or otherwise make variables dynamic but not how to use these variables to retrieve properties) and trying I finally decided to ask for help. I have been trying to use dynamic variables to get properties of an object, first outputting my information to JS objects, and after that getting values from dropdown select elements and a string, combining all that information to one string, and after that using that string as object.property. But what I finally get as a result is just output string which seems correct, but it's printed out just as a string, not working as object.property. Propably this is just something small I just can't figure out, or perhaps my approach is just totally wrong. Also already tried the same by outputting to hidden table elements, and then changing hidden=false, but the result was more or less the same. By hardcoding the string to work as the object.property I get the result I'm looking for, this done just to test my objects. Using object constructor that seems working ok:  function myCar(carClass, id, brandType, price) { this.carClass = carClass; this.id = id; this.brandType = brandType; this.price = price; };  When fetching database information myCar or object variable name gets to be for example "sedan_car_audi", and other information goes in their respective places. The dropdown information comes from here: 

myCarType Title: myCarBrand Title:

 And script where I try to make the combined variable( or actually here are couple of ways I've tried) and use document.getElementById to get the result for example sedan_car_audi.price , but what I get is only the string "sedan_car_audi.price" as the result, not the price property value.. (which works ok for showing it on the "demo10":   I hope this is clear enough, this is modified version of my real code, but should be accurately copied/modified. Sleepless nights and grayed hair would hugely appreciate any help.
 You need to login account before you can post.
Processed in 0.316187 second(s) , Gzip On .