javascript: Creating and accessing new window DOM

XOR != OR

[H]F Junkie
Joined
Jun 17, 2003
Messages
11,547
Hi all,

I have a project where I have a new window called based on a text field in the parent window. The new window is called correctly and everything opens fine. I retain a pointer to the new window in the parent window.

The problem is, I can't write anything from the parent window to the child window.

So, without further ado, here's the code in question:
Code:
  <input type="text" id="requestor" name="requestor" value='' onChange="newRequestor( this )" />
<script>
  requestorList = new Array( {REQ_LIST} );
  actb(document.getElementById('requestor'),requestorList);
  function newRequestor( obj )
  {
    var newUserEntry;
    found = false;
    for( var i = 0; i < requestorList.length; i++ )
    {
      if( obj.value == requestorList[i] )
      {
        found = true;
        break;
      }
    }
    if( found == false )
    {
      if( confirm( "'"+ obj.value +"' not found in database, do you wish to add them?" ) )
      {
        if( !newUserEntry || newUserEntry.closed )
        {
          newUserEntry = window.open( "newRequestor.php", "newUser", "status,height=400,width=400,dependant" );
          newUserEntry.document.forms["requestorForm"].lname.value="test";
        } else
        {
          newUserEntry.focus();
        }
      }
    }
  }
</script>
As you can see, i use the onchange event. Without going into too much detail, I check the new value against an array, and if it isn't in there, it pops open the new window which is a form to add this 'requestor'.

However, when I open the new window, I have no text in the lname input element .

If anybody has any experience and can explain this behavior to me, I'd appreciate it.

edit: And I know my javascript sucks. I'm just learning it, and quite frankly, I think the language was designed by someone clinically insane.
 
make newUserEntry global (i.e. move the var declaration outside of the function, like your array)? Since it is scoped inside the function it does not persist once that function finishes executing.
 
You are tyring to set the value of the lname input before it exists -- you aren't allowing any time for your pop-up to open and for newRequestor.php to load.

Instead of pushing the value to the pop-up, try using onload/onfocus events in newRequestor.php to grab your value from the opener document.
 
HeThatKnows said:
You are tyring to set the value of the lname input before it exists -- you aren't allowing any time for your pop-up to open and for newRequestor.php to load.

Instead of pushing the value to the pop-up, try using onload/onfocus events in newRequestor.php to grab your value from the opener document.
ooo, thanks. that'll probaly work.

generelz, i did try settimeout, with 100ms, but that didn't seem to work.

thank's again for the ideas, i'll let you know how they work out.
 
Back
Top