faqts : Computers : Programming : Languages : JavaScript : Forms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

6 of 8 people (75%) answered Yes
Recently 6 of 8 people (75%) answered Yes

Entry

I have one link opening a new window, how do i get the 2nd link to prefill the form fields in windw?

Sep 23rd, 2002 06:29
Jean-Bernard Valentaten, Iain Waugh,


This shouldn't be a problem, since using the window object you can 
access the document object of any popup you have generated, as long as 
you have kept a reference to that popup in a variable:
var myWin = '';
function openWin()
{
  myWin = window.open('someUrl', 'someTitle', 'the specs');
}
function prefillForm()
{
  if (myWin != '')
  {
    if (myWin.document.myForm)
    {
      myWin.document.myForm.myElement1.value = 'some Value';
      myWin.document.myForm.myElement2.value = 'some Value';
      myWin.document.myForm.myElement3.value = 'some Value';
      myWin.document.myForm.myElement4.value = 'some Value';
    }
  }
}
Now in the a-tags you'll write something like this:
<a href="javascript: openWin();">Open Popup</a>
<a href="javascript: prefillForm();">Fill it up</a>
That should work.
HTH,
Jean