Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Window - Passing a value to the child window ? 3

Status
Not open for further replies.

crabsodyinblue

Programmer
Aug 22, 2001
14
0
0
Hi

I was wondering if anyone can help with a problem of passing a variable to a pop up window so it can be used in that window.

I have a form on my main calling html where one of the field name is filenametopass in a form titled menufrm

on the click of a submit button I am calling a piece of javascript code to open in a new popup window a template htm file.

Ideally I want the popup window (child window) to get the value of the field filenametopass from the calling window , so I can use this value to load an xml file with its corresponding xsl file in the child window.

The idea is the child window to use a javascript snipet of code to get the value filenametopass from the opening window.

Although it is possible to use the url when not using javascript to open the popup window. I want the popup window to appear on screen with no address bar.

My problem is how do I pick up the value of the variable from the calling opener window in the child popup window.

Any help would be great.

Regards
Glenn

 
See if this works...

main.htm
<script>
var passedVal = &quot;Hello&quot;
window.open(&quot;child.htm&quot;)
</script>


child.htm
<script>
getVal = window.opener.passedVal
alert(getVal)
</script>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
Thanks for the reply

Yes your example works for a simple example, however
I am using a form with a couple selection boxes , and I am making up a variable by combing the two results of the selection boxes.

After selecting two values from selection boxes , I am creating a variable when I click on a button. The button is designed to perform a javascript script which combines the two results and places the value in a variable.

The idea was to open a window and pass this value.

Here is an example of what I am trying to do , unfortunately I am getting undefined poping up on my alert box.

Calling (Initial window)
<html>
<head>
</head>
<body>

<form name=&quot;testwindowcall&quot;>
<input type=button value=&quot;Test pass of variable to window&quot; onClick=&quot;wincaller()&quot;>
</form>

<script>
function wincaller()
{
str1=&quot;abc&quot;;
str2=&quot;123&quot;;
var passedVal = str1 + str2;
window.open(&quot;called.htm&quot;);
}
</script>


</body>
</html>


The called (child/popup) window is called called.htm
and the example test code is

<html>
<head>
</head>
<body>

<script>
getVal = window.opener.passedVal
alert(getVal)
</script>

</body>
</html>

I have uploaded to personal web space an example of this at


please excuse the non business domain as it is personal web space.

I have also uploaded an example of your original reply at



please note I am attempting this using purely javascript , as the end result may be used when the user is not necessarily connected to the internet.

Regards and thanks
Glenn
 
your var &quot;passedVal&quot; is scoped locally to the function...you can make it global like so:


function wincaller()
{
str1=&quot;abc&quot;;
str2=&quot;123&quot;;
window.passedVal = str1 + str2;
window.open(&quot;called.htm&quot;);
}




=========================================================
while (!succeed) try();
-jeff
 
Hello Jeff

Thanks very much for the tip regarding making the variable global , works perfectly.

Regards
Glenn


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top