Link to home
Start Free TrialLog in
Avatar of Vehemence
Vehemence

asked on

Updating the innerHTML of a dynamically created/named SPAN tag

The only problem I'm really having with this code (although it may look butchered in other places, I know what I'm doing.. honest ;) ) is the updating of the dynamically created and named (with the current time) span tag with a 'new' string from the jd[] array. Is updating a dynamically created span tag (or div, for that matter) even possible? If so, HELP! :)


function banner() {}
     jd = new banner() ; n = 0;
jd[n++]= '<A HREF="https://www.experts-exchange.com"><IMG SRC="http://www.mydomain/mybanner01.gif" border=0></A>';
jd[n++]= '<A HREF="https://www.experts-exchange.com"><IMG SRC="http://www.mydomain/mybanner02.gif" border=0></A>';
jd[n++]= '<A HREF="https://www.experts-exchange.com"><IMG SRC="http://www.mydomain/mybanner03.gif" border=0></A>';

     i=Math.floor(Math.random() * n);
     var day = new Date();
     var somename = day.getTime();

     document.write('<span STYLE="position: absolute;" id="' + somename +'">');
     document.write(jd[i] + '<br><a href="javascript:bannerchange(\''+somename+'\',\''+i+'\')">Click to update the banner</a>');
     document.write('</span>');


function bannerchange(bannerspan,numb){
ns4 = (document.layers)? true:false
ie4 = (document.all)? true:false
var numbOne=i++;
var bCode=jd[numbOne];
  if (!ie4) {
    with (document[bannerspan].document) {
      open();
      write(bCode + '<br><a href="javascript:bannerchange(\''+somename+'\',\''+i+'\')">Click to update the banner</a>');
      close();
    }
  }
  else {
    document.all[bannerspan].innerHTML = (bCode + '<br><a href="javascript:bannerchange(\''+somename+'\',\''+i+'\')">Click to update the banner</a>');
  }
}
Avatar of Vehemence
Vehemence

ASKER

Note: Even if I've balls'ed the code and it's not updating what I need it to update, that's alright.. I just need it to be able to change the inside of the tag to *anything* and I can work from there
ASKER CERTIFIED SOLUTION
Avatar of nimaig
nimaig
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, that seems to be all that was holding it back.. something I'll remember to look out for from now on (and would never have thought to check myself!)
I also think that the i isn't incremented the first time you call the function.

var numbOne=++i;