Web Analytics Made Easy -
StatCounter dynamic content and variables - CodingForum

Announcement

Collapse
No announcement yet.

dynamic content and variables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

  • #2
    Hope this helps
    Code:
     
    for(I=0;I<12;I++)
    {
    document.getElementById('dcontent'+I).innerHTML=mycontent[I]
    }

    Comment


    • #3
      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...

      Comment


      • #4
        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

        Comment


        • #5
          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
          vBulletin Mods That Rock!

          Comment

          Working...
          X