Solved

Updating the innerHTML of a dynamically created/named SPAN tag

Posted on 2001-06-21
4
156 Views
Last Modified: 2008-02-20
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="http://www.experts-exchange.com"><IMG SRC="http://www.mydomain/mybanner01.gif" border=0></A>';
jd[n++]= '<A HREF="http://www.experts-exchange.com"><IMG SRC="http://www.mydomain/mybanner02.gif" border=0></A>';
jd[n++]= '<A HREF="http://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>');
  }
}
0
Comment
Question by:Vehemence
  • 2
4 Comments
 

Author Comment

by:Vehemence
ID: 6213619
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
0
 
LVL 9

Accepted Solution

by:
nimaig earned 200 total points
ID: 6213843
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
0
 

Author Comment

by:Vehemence
ID: 6213874
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!)
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6213886
I also think that the i isn't incremented the first time you call the function.

var numbOne=++i;
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now