View Full Version : dynamic content and variables

02-06-2004, 10:49 PM
I have used the principle of the example at this page: http://www.javascriptkit.com/javatutors/dynamiccontent5.shtml several times quite successfully. (Thanks for the tutorials!!) I am now trying to set up a page with 12 different graphics which I wish to be able to manipulate individually. I could write <div id="dcontent1"... through <div id="dcontent12"... and use dcontent1.innerHTML=mycontent[i]; through dcontent12.innerHTML=mycontent[i]; but it seems there must be some way using variables to do the equivalent of id="dcontent+x" and dcontent+x.innerHTML=mycontent[i]; for x = 1 to 12 (excuse the crude symantics)
Any advice appreciated.

02-06-2004, 11:00 PM
Hope this helps


02-07-2004, 01:13 AM
Thanks for the reply,
I was hoping I could extrapolate from the replies, but it looks like I need a little more help.
for the other half, would:
document.write('<div id="dcontent'+I+'"....
be correct ?
And how would the equivalent lines for NS 4/6 work?
Thanks again.
P.S. I like your quote. Too true...

02-07-2004, 07:28 PM
Hi again,
Actually I was able to extrapolate with your advice. Thanks.:thumbsup:
Could I ask two more related questions?
1) am I correct in assuming that getElementById wouldn't work for ie4 and if so is there an easy alternate option? Would
document.all['dcontent'+I].innerHTML=mycontent[I] do the job?
2) How does IE 5.1 on Mac (That's what many of the classroom PC's use) fit in ? Will it work with getElementById .

02-09-2004, 04:02 AM
if (document.getElementById){
//use document.getElementById
else if (document.all){
//use document.all

IE4 uses document.all
IE5+ uses both document.all and document.getElementById
NS6+/Moz and other modern browsers use document.getElementById

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum