tags:

views:

602

answers:

3

Hi I am desparate now to find a solution to this problem. I'm trying to call a function on the onclick even inside another function. The event works fine if the parameters are static. I want to get a the value from the global function. The example is as follows:

var dataxml = unescape(xml);    
var xmldoc = getDomAdapter().parseXml(dataxml);
var rootnode = xmldoc.getElementsByTagName('result_set')[0];
var newsresult = rootnode.getElementsByTagName('item');
var pages = Math.round(newsresult.length / 10);

for (var p=1; p <= pages;p++){

pagesref = pagesref+"<a  href='#' onclick='newsdatainfo(xmldoc,newsresult,6,10);' >"+p+"</a> | ";
}

How do I get the xmldoc and newsresult to be identified? Because I get an undentified error message.

I will be greatfull if you help me.

Thanks Mamcy

A: 

Did you try "document.xmldoc"?

What scopes are the variable definitions in? If they are private (within a function), they will not be visible from outside that function. In this case, you would need to make them either global (put them into the document's scope), or create closures for your onclick handlers.

Thilo
A: 

It looks like it should work if you are indeed setting the variables globally as you say. But for a precaution, i would initalize the newsresult and xmldoc variables inside the function itself (just before the loop) and see if it helps

Click Upvote
A: 

You could also try observing the click event (choose favorite framework here)

prototype: $(ele).observe('click').newsdatainfo() and refactoring the scope of things might make the code cleaner and easier to maintain.

if your mixing HTML and Javascript, your usually on the wrong track.

jminkler