Jump to content

<a onclick=..> not working inside javascript


mona

Recommended Posts

hi, I have a problem, I have the below code where the table and href shold be inside javascript using document.writeif I put onclick="..." inside the <a > It's not working and I have eror on page after clickingwhat is the problem? <html><head><script language="JavaScript">function submitting(forum){document.write(forum) //this is only a test}function loading(){var xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.load("forums.xml"); var doc=xmlDoc.documentElement; for(var i=0; i<doc.childNodes.length; i++) display(doc.childNodes(i));}function display(cat){document.write('<a name="top"></a><TABLE cellspacing="1" width="100%" bgcolor="#99ccff" border="2" ><TR><TH bgcolor="#ffff99" COLSPAN="3" ALIGN="LEFT">'+cat.getAttribute("NAME")+'</TH></TR>');document.write('<TR bgcolor="#33cccc" ><TD width="80%">Forum</TD><TD width="10%">Topics</TD><TD width="10%">Replies</TD></TR>');for(var j=0;j<cat.childNodes.length;j++){var node=cat.childNodes(j);document.write('<TR><TD><a href="#top" onclick="submitting(\''+node.childNodes(0).firstChild.text+'\')">'+node.childNodes(0).firstChild.text+'</a><br><FONT COLOR="GRAY">'+node.childNodes(1).firstChild.text+'</FONT></TD><TD>'+node.childNodes(2).firstChild.text+'</TD><TD>'+node.childNodes(3).firstChild.text+'</TD></TR>');}document.write('</TABLE>');}</script></head><body onload="loading()"><form name='forums' action='posts.php' method='post'><input type='hidden' name='forum'/></form></body></html>but if I tried alert instead of submitting it works:

Link to comment
Share on other sites

hi MONA.....i think u need to check the following lines in your code,what i found is almost correct....the document.write('<a name="top"></a><TABLE cellspacing="1" width="100%" bgcolor="#99ccff" border="2" >><TR><TH bgcolor="#ffff99" COLSPAN="3" ALIGN="LEFT">'+cat.getAttribute("NAME")+'</TH></Tplease do check the <a name="top">...</a>here you need to insert the table content and the for loop with the parent and child tags.or describe some action that makes to run the for loop in the <a> .....</a> tag

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...