Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Updating the innerHTML of a dynamically created/named SPAN tag

Posted on 2001-06-21
4
Medium Priority
?
165 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 800 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Suggested Courses

877 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