Page 1 of 1

Variables in the Javascript DOM

Posted: Mon Dec 12, 2005 4:56 pm
by denz
Hi all

I would like to update a field on the web page based on a radio button checked. The radio button has the same id as an image, so if i select radio button with the id of 6 i would like to be able to get the src of img with the id of 6 and move it the the opener page

i've tried this:

Code: Select all

opener.document.img1thumb.src = "test.jpg"
which works perfectly

however when i try this:

Code: Select all

opener.document.img1thumb.src =  document.img + imgdat +.src
i get a syntax error. (btw, i have a small function that loads the id of the checkbox into a variable called imgdat)

any ideas how to pass a variable into the DOM?

Thanks

Posted: Mon Dec 12, 2005 5:02 pm
by Burrito
take a look at getElementById().

something like:

Code: Select all

document.getElementById('img'+imgdat).src
should work.

Posted: Mon Dec 12, 2005 5:08 pm
by denz
Wonderful, you're a hero again!

8)