Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-06-2004, 10:49 PM   PM User | #1
BCRandCo
New Coder

 
Join Date: Mar 2003
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
BCRandCo is an unknown quantity at this point
dynamic content and variables

Hi,
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.
Thanks
Michael
BCRandCo is offline   Reply With Quote
Old 02-06-2004, 11:00 PM   PM User | #2
Garadon
Regular Coder

 
Join Date: Jul 2002
Posts: 698
Thanks: 0
Thanked 0 Times in 0 Posts
Garadon is an unknown quantity at this point
Hope this helps
Code:
 
for(I=0;I<12;I++)
{
document.getElementById('dcontent'+I).innerHTML=mycontent[I]
}
Garadon is offline   Reply With Quote
Old 02-07-2004, 01:13 AM   PM User | #3
BCRandCo
New Coder

 
Join Date: Mar 2003
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
BCRandCo is an unknown quantity at this point
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.
Michael
P.S. I like your quote. Too true...
BCRandCo is offline   Reply With Quote
Old 02-07-2004, 07:28 PM   PM User | #4
BCRandCo
New Coder

 
Join Date: Mar 2003
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
BCRandCo is an unknown quantity at this point
Question

Hi again,
Actually I was able to extrapolate with your advice. Thanks.
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 .
Thanks
Michael
BCRandCo is offline   Reply With Quote
Old 02-09-2004, 04:02 AM   PM User | #5
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
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
__________________
Glenn
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:52 PM.


Advertisement
Log in to turn off these ads.