PDA

View Full Version : problem in calling a js function from another function


kush04
02-08-2008, 06:16 AM
Hi Guys. Im currently working on a code that makes use of Javascript and XML DOM. The open-win() function is working perfectly fine and pops up a new window when called. But the problem is that im not able to call dispval() function from within the open_win() function using the onclick event of the button. I have highlighted it. Thanks in advance.


<html>
<head>
<script language="JavaScript" type="text/javascript">
var xmlDoc;
var nwin;
var artselind;
function open_win()
{

var ls=document.presform.fname.value;
if (ls="http://www-scf.usc.edu/~csci571/2008Spring/hw4/rss2.xml")
{

if (window.ActiveXObject)
{
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");


}

if (document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument("","",null);

}
nwin=window.open("","assign","height=500,width=800");
xmlDoc.async=false;
var loaded=xmlDoc.load("a.xml");
var tit=xmlDoc.getElementsByTagName("title");
nwin.document.write("<h3><p align='center'>A New York Times Blog</p></h3>");
nwin.document.write("<form name='main'><select name='articles' id='artid'>");
nwin.document.write("<option selected='selected'>Choose an Article</option>");
for (i=1;i<tit.length;i++)
{ nwin.document.write("<option>" + tit[i].childNodes[0].nodeValue + "</option>");

}


nwin.document.write("</select>");
nwin.document.write("<input type=button value='Show Article Details' onclick='dispval()' />");
nwin.document.write("</form>");

}

}

function dispval()
{
nwin.document.write("nothing gets displayed");

}
</script>
</head>
<body>
<h1>View Articles</h1>
<form name="presform">
<font size="5">Enter XML File</font><br><br>
<input type="text" id="link" name="fname" size="80">
<br><br>
<input type=button value="Submit Query" onclick="open_win()" />
</form>
</body>
</html>

A1ien51
02-08-2008, 04:26 PM
You function is in the parent window and not in the pop up window. You would have to use window.opener.functionName() to call it.

Eric

kush04
02-08-2008, 10:35 PM
thanks man !! It worked!! Thanks a ton!!