tags:

views:

392

answers:

2

The I wrote in the <a href='javascript:newsdatainfo(document.xmldoc,...see below. But it still does not work.

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);

var pagesref;
for (var p=1; p <= pages;p++){
    if (p==1)
        pagesref = pagesref+"<a href='javascript:newsdatainfo(document.xmldoc,document.newsresult,6,10)' >"+p+"</a> | ";
A: 

It looks like you are trying to call the javascript in the HREF field, not the onClick field.

It is hard to tell what you are asking, but maybe that will help you.

Kevin Crowell
A: 

Echoing other responses I don't know quite what you're asking here. In particular never say "it doesn't work - state what actions you performed, what your expected output was and what your actual output was. Though anyway:

  1. You shouldn't use a javascript: prefix in a href; you should actually use the onclick event that you referenced in your question title.
  2. You can just use xmldoc and rootnode unprefixed.
  3. If you don't want the hyperlink to actually go anywhere, make sure you return false from the onclick handler to prevent the click from being handled. Also set the URL to "#" (which will typically point to the top of the current page), so that the link will degrade gracefully with Javascript disabled and so that the address in the status bar on hover makes sense (unless you want to override that too).
  4. I hope that code ends abruptly, since looping over all elements just to perform some action on the first one is suboptimal, to say the least.

Thus I believe your last line could be written as

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

and things might work as you expect, however that may be.

Andrzej Doyle