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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass value to new window 1

Status
Not open for further replies.

skibascott

IS-IT--Management
Mar 18, 2004
82
US
I am opening a new window with this code:

Code:
newWin = window.open('standards.htm', 'standards');

This standards.htm doc is an existing doc with more code in it. I need to use the values of four text fields in standards.htm. Can I reference these fields with javascript code? Or do i need to pass them somehow?

Thank you.
 
You can build a query string for your window.open statement.

Code:
var myQS = "?myTextBox=" + document.getElementById("myTextBox").value;

var newWin = window.open('standards.htm'+myQS, 'standards', '');

Then your standard.htm page would process the querystring using the "location.search" object.

Or, standard.htm could directly interrogate the values from the parent page, by using "self.opener":

Code:
window.alert(self.opener.document.getElementById('myTextBox').value);

That code in the child window would display the value of "myTextBox" from the parent window.



Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
I am looking for an explanation about clflava's post.
 
say standards.htm has a form:

Code:
<form name="f">
  <input type="text" name="t" value="something" />
</form>

now lets say in your main page, you have one button that does this:

Code:
<input type="button" name="b" onclick="doMyThing();" value="open window" />

and a function (with a global variable):

Code:
var myWin;
function doMyThing() {
    myWin = window.open('standards.htm','standards','');
}

and a second button:

Code:
<input type="button" name="b2" onclick="alert(myWin.document.forms['f'].elements['t'].value);" value="show value" />

Does this clarify anything?

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
I am trying to use variables from the main page in standards.htm.

Thanks.
 
I thank both of you for your suggestions. I used the "self.opener" code to reference the variables. Works great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top