The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [Solved] Trouble Using Variable in GetElementById Reply To: [Solved] Trouble Using Variable in GetElementById


Hmm, the names do match, but maybe there’s a better way to check? I just set up an alert to pop up the value of “selected” at the beginning of the infobox function – it does go through all 4 of them and they match the names of the divs. If I take that a step further and ask it to pop up document.getElementById(selected), it starts saying [object HTMLDivElement] for each one. If I do document.getElementById(selected).value, then it’s “undefined.”

It feels like even though the right variables are plugging in, it still can’t find the div. It’s on the same page and everything ( Any other suggestions for how to crack this?

I updated the pen with the HTML code as well:

Thanks for your help!