Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2003
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 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
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hope this helps
    Code:
     
    for(I=0;I<12;I++)
    {
    document.getElementById('dcontent'+I).innerHTML=mycontent[I]
    }

  • #3
    New Coder
    Join Date
    Mar 2003
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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...

  • #4
    New Coder
    Join Date
    Mar 2003
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •