javascript - Having trouble referring to object within array -


i trying write html page class uses drop down menu allow users pull list of relevant information. unfortunately having trouble figuring out how make script call on information in array. jsfiddle has full html section, appreciated.

please bear in mind not terminology, specific possible. regarding jquery, our teacher didn't go on it's freaking mystery me.

also, plan on adding more information objects in array, until working, don't want waste time on might need restructure.

http://jsfiddle.net/gamergorman20/nw8ln6ha/11/

 var favwebcomics = [     goblins = {1: "www.goblinscomic.org"},     girlgenious = {1: "www.girlgeniousonline.com"},     grrlpower = {1: "www.grrlpowercomic.com"}     ];      var myfunction = function() {         var x = document.getelementbyid("myselect").value;          document.getelementbyid("demo").innerhtml = "you selected: " + x;         document.getelementbyid("web").innerhtml = favwebcomics.x;     }; 

again, jsfiddle link has full html, there unused items currently, plan on adding more of them soon.

my next plan incorporate images objects, picture loads each selection option. how manage that?

[ ] used arrays, indexed numbers. if want named properties, should use object, uses { } literals:

var favwebcomics = {     goblins: "www.goblinscomic.org",     girlgenious: "www.girlgeniousonline.com",     grrlpower: "www.grrlpowercomic.com" }; 

= assigning variables, not specifying property names in object.

then need understand difference between . , [] notation accessing objects. .x means property literally named x, [x] means use value of x property name. see dynamically access object property using variable.

so should be:

document.getelementbyid("web").innerhtml = favwebcomics[x]; 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -