Solved

Updating the innerHTML of a dynamically created/named SPAN tag

Posted on 2001-06-21
4
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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

635 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