views:

30

answers:

2

I have a list of people wrapped in a-tags with onclick for opening a popup window.

That popup window contains a previous and next button that invoker a function in the parent window to get the previous/next a-tag and execute the onclick for it.

nextAnchor.onclick();

This should update the popup window with the new persons info, but it doesn't update. Adding an alert("") right after makes it update. What i found searching is something about having to leaving the session before JavaScript will update the display and they suggested using setTimeout.

Problem is i'm calling on a DOM element and i can't send it in to the setTimeout, so i ended up with

setTimeout('eval("'+nextAnchor.getAttribute("onClick")+'")',10);

So is there another way to make it update or a way of making the setTimeout use the onclick of a DOM element or is this an acceptable solution even though it uses eval?

A: 

If your concern is just eval then why not this:

setTimeout('goNext',10);

function goNext()
{
   nextAnchor.getAttribute("onClick");
}
Nivas
nextAnchor is local variable for the function its created in and there for wont be able to call it from the goNext functionthe ideally solution would be something like setTimeout('nextAnchor.onclick()',10); i could make it so the other function could get the nextAnchor but then i would say it is better code to use eval since the source is secure
Blem
A: 

If that is the case, you can try this:

setTimeout(function(){myFunction(parameter)},myTimeout);

(stolen from here)

See also the first comment in the post.

Nivas
this was what i needed :)didnt need to make an extra functionsetTimeout(function(){nextAnchor.onclick()},10);
Blem