Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

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=""><IMG SRC="http://www.mydomain/mybanner01.gif" border=0></A>';
jd[n++]= '<A HREF=""><IMG SRC="http://www.mydomain/mybanner02.gif" border=0></A>';
jd[n++]= '<A HREF=""><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>');

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) {
      write(bCode + '<br><a href="javascript:bannerchange(\''+somename+'\',\''+i+'\')">Click to update the banner</a>');
  else {
    document.all[bannerspan].innerHTML = (bCode + '<br><a href="javascript:bannerchange(\''+somename+'\',\''+i+'\')">Click to update the banner</a>');
  • 2
1 Solution
VehemenceAuthor Commented:
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
I don't think you can have the name of an object as only numbers. Try appending a character to the number like this :

var somename = day.getTime() + "a";

try this. It work with IE
VehemenceAuthor Commented:
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;
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now