• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 801
  • Last Modified:

Javascript: populating fields in a child window

I have an applicaiton in which I have two buttons which need to open the same child window.....but I need to know which button opened the child window

so button 1 = openChildWin("Rej")
and button2 = openChildWin("Cancel")

the function openChildWin uses the window.open(url, name, options)....so what I'd like to do is take the parameter coming in (eg "Rej" or "Cancel") and load that into a field on the child form......so when the child form is saved, I can use the "opener.document........to retrieve the value.

best regards
Barry
0
barrylewin
Asked:
barrylewin
  • 3
  • 3
1 Solution
 
lpxtechCommented:
Hi,

You can access the DOM of the child window by using name.document.

For example if you have an input field with the id="myInput"... See the code attached.
<script type="text/javascript">
  function OpenChildWin() {
    var wopts  = 'width=300,height=500,resizable=1,alwaysRaised=1,scrollbars=1';
    var childW = window.open('http://www.myurl.com/', 'childWin', wopts);
  }
  ChildWin.document.getElementById("myInput").value = "Hello...";
</script>

Open in new window

0
 
barrylewinAuthor Commented:
I tried your code out, but the "myInput" field isn't getting populated with the value....once the child window is open, I do a view source and the field is blank....

in my code snippet, WebActiion is being passed into the function, and I"m trying to get it to be written to the child window

function openMsgWindow(WebAction ) { 
winURL = path + "Msg?OpenForm"; 
                     winName = "ChildWin"; 
                        winOpts = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=200,screenX=200,screenY=200"; 
                 ChildWin = window.open( winURL, winName, winOpts ); 
                 ChildWin.document.getElementByID("WebAction").value = WebAction
}

Open in new window

0
 
lpxtechCommented:
The values must be put in after the child window has finished loading.

Try the following code.
// Add to parent window:
 
function doneloading() {
        // Do what you want after the window has loaded.
	ChildWin.document.getElementById("myInput").value = 'Test...';
}
 
// Add to child window:
 
<script type="text/javascript">
	window.onload = function() {
		window.opener.doneloading();
	}
</script>

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
barrylewinAuthor Commented:
I think your last solution has a logic error....I'm trying to load the field in the child win with a VARIABLE that gets passed into the "openMsgWindow" function....

so the "doneloading" function isn't going to know which value to load

how about this idea?
in the main forms' button....I save the field on the main form
then use your idea of in the onload of the child window, go get the main form's field

thanks for your help
barry
0
 
lpxtechCommented:
Yes, that should work if I understand what your saying,

You want to create a global variable in the parent, var myVar; then set that variable in the open window function and set the field values in the doneloading function correct?

If so, that should be fine. Either way, you will have to execute any code you want on the child window in the doneloading function
0
 
barrylewinAuthor Commented:
got it to work...thanks alot for your help..

best regards
barry
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now