4 Replies - 649 Views - Last Post: 02 October 2009 - 08:54 AM

#1 ktalebian  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 08-April 08

The code does not work all the time!

Posted 02 October 2009 - 05:37 AM

Hi there,

I am using the code from the webpage
http://web-graphics....hive/001717.php
I'm modifying it so that the bubble loads some data from another website.
Now, the original code runs when the page reloads.
I changed it so that it runs when I move my mouse over the link. It worked, except that you had to move the mouse at least twice before you get the bubble (first time to initialize it).
So I wrote another function that would load on page, and would initialize it.
Its as followed:
function initTooltips(toolBar)
{
	var numLink,i,nameLink;
	numLink = document.getElementById(toolBar).getElementsByTagName("a");
	for( i=0;i<numLink.length;i++)
	{
		nameLink = "catLink"+numLink[i].name;
		runTooltips(numLink[i].name,nameLink);
	}
}



Now problem is that when I run this, it only initializes the last link! HOWEVER, if I put an alert() function in the for loop, and then press okay the number of times it shows up, THEN all links are initialized!! Why??

Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: The code does not work all the time!

#2 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: The code does not work all the time!

Posted 02 October 2009 - 06:05 AM

I think this is because you're calling your runTooltips function too quickly in sequence. Can you post the runTooltips function, and any variables that are created outside of the functions?
Was This Post Helpful? 0
  • +
  • -

#3 ktalebian  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 08-April 08

Re: The code does not work all the time!

Posted 02 October 2009 - 06:35 AM

Hi and thanks for the reply.

Well, this is the runTooltips
function runTooltips(cID,lID)
{
	var links,h;
	h=document.createElement("span");
	h.id="btc";
	h.setAttribute("id","btc");
	h.style.position="absolute";
	document.getElementsByTagName("body")[0].appendChild(h);
	links = document.getElementById(lID);
	prepareLink(links,cID);
}



prepareLink basically then creates a HTTP request file, and then gets some information from another website, and then that calls the function that will create the bubble effect.

I also thought that this is because it is loading too fast, so I added a little delay loop inside it, and even after setting it to like 10 seconds, it still did not work! It only works when I use alert() (so I am pausing the whole process).

Cheers
Was This Post Helpful? 0
  • +
  • -

#4 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Re: The code does not work all the time!

Posted 02 October 2009 - 07:04 AM

It looks like every time you are calling that function you are creating a new span with the same id. Id's should be unique so maybe create a counter outside of your function that can be incremented with every function call. The use that value to assign unique a new id each time:
var myCounter = 0;
function runTooltips(cID,lID)
{
	var links,h;
	h=document.createElement("span");
	h.id="btc"+myCounter;
	h.setAttribute("id","btc"+myCounter);
	myCounter++;
	h.style.position="absolute";
	document.getElementsByTagName("body")[0].appendChild(h);
	links = document.getElementById(lID);
	prepareLink(links,cID);

}



Admittedly I'm not testing this as I go, it's all just conjecture. Hope it helps!
Was This Post Helpful? 0
  • +
  • -

#5 ktalebian  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 79
  • Joined: 08-April 08

Re: The code does not work all the time!

Posted 02 October 2009 - 08:54 AM

Hey,

I tried that, and this actually does not even let the script work! Apparently, we only have one span that is just moved in position!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1