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!

Sending values from one window to another 1

Status
Not open for further replies.

szgr

Programmer
Nov 7, 2001
4
0
0
GB
All,
I have the following function which takes a value from a text input box, then onclick of a button, opens another small window with the value displayed in it. However, if I don't put the alert in the script, the function doesn't work. Any ideas??

function openwindow() {

userwindow = window.open("remote.html","widthwindow", "toolbars=no, menubars=no, width=200, dependent=true, location=no, height=300, resizeable=no" );
alert();

userwindow.document.calWidth.receiver.value=document.myform.mywidth.value
}

text box code
<pre>width:
<input
type=text
value=&quot;&quot;
id=widthbox
size=5
maxlength=5
name=mywidth>

button code
<input
type=&quot;button&quot;
value=&quot;open window&quot;
onClick=&quot;openwindow();&quot;>

Thanks

Steve
 
Hi Steve,

I think the problem is that the document hasn't finished loading in the new window yet. The alert dialog in the parent window will delay things long enough for this to happen.

If you need to pass a value across you could always pass it via the url. i.e.

Code:
var url = &quot;remote.html?&quot; + document.myform.mywidth.value;

userwindow = window.open(url, &quot;widthwindow&quot;, &quot;toolbars=no, menubars=no, width=200, dependent=true, location=no, height=300, resizeable=no&quot; );

then in the child window you could can retrieve the value using...

Code:
var value = location.search.substring(1);
Bill Bruggemeyer
&quot;It ain't what you do, it's the way that you do it!&quot;
 
Instead of opening the new window and putting the value into a field in it (Bill's right, it may not have finished loading yet), open the new window and have it's onLoad event (in the body tag) fetch the value into itself from the parent window. I.E.
Code:
<body onLoad=&quot;document.calWidth.receiver.value=parent.document.myform.mywidth.value&quot;>
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top