Click to See Complete Forum and Search --> : Pass JS variable to another frame


kjgerard
03-01-2004, 12:19 AM
Elementary javascript function has me stumped...

I want to pass a javascript function variable via onClick in Frame A for display in a <div> layer within Frame B.

In the code below, I get "undefined" displayed as my variable instead of "this content" (the text function variable I'm attempting to pass to frame B):

Frame A

onClick="parent.frameB.functionName('this content')"

Frame B

<head>
<script type="text/javascript">
function functionName(functionvariable)
{
return(functionvariable)
}
</script>
</head>

<div id="layer1">
<script type="text/javascript">document.write(functionName())</script>
</div>

Any help is greatly appreciated.

fredmv
03-01-2004, 01:31 AM
Welcome to the forums. frameset.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>untitled</title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
</head>
<frameset cols="50%, *">
<frame src="framea.html"></frame>
<frame src="frameb.html"></frame>
</frameset>
</html> framea.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>untitled</title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
</head>
<body>
<h1>Frame A</h1>
<p>
<a href="#" onclick="parent.foo='some content';parent.frames[1].document.getElementById('out').firstChild.nodeValue=parent.foo;">Create variable and pass it to Frame B</a>.
</p>
</body>
</html> frameb.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>untitled</title>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=iso-8859-1" />
</head>
<body>
<h1>Frame B</h1>
<div id="out">
&amp;nbsp;
</div>
</body>
</html>