Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Using JavaScript how to pass parent form value to child

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I pass a parent form value to a child form? I have the following code.
var newWin = window.open('getInfo.jsp','newWindow','height=200,width=500,location=no,toolbar=no,scrollbars=no,resizable=no,left=0,top=0');
newWin.document.childForm.personName.value = document.parentForm.personName.value;
The child window opens but the parent window has a JavaScript error: 'document.childForm.personName' is null or not an object. The parent value is not passed to the child.
What do you suggest?
Thanks for your time and help!
Tiffany
 
Tiffany Collins
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it.
In getinfo.jsp body onload tag:
document.childForm.personName.value=window.opener.document.parentForm.personaName.value
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will tell you the reason why you were getting the error and why your solution fixed it.
The parent would call it right after it called the window.open method.
The problem is that it happens so quick that the form and its elements in the child were never written to the page in time.
The onload event waits until that page is fully loaded then it firs the code.
Hope that gives you some insight to what happens.
Eric
 
It's fun to be me, and still legal in 9 states! Wanna see my tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic