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, name, options) 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 when the child form is saved, I can use the " retrieve the value.

best regards
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


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 ='', 'childWin', wopts);
  ChildWin.document.getElementById("myInput").value = "Hello...";

Open in new window

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 = winURL, winName, winOpts ); 
                 ChildWin.document.getElementByID("WebAction").value = WebAction

Open in new window

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() {

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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
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
barrylewinAuthor Commented:
got it to work...thanks alot for your help..

best regards
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.