2

twoI am trying to write back some values to a parent page and have written the following but it is saying that SCRIPT5007: Unable to get value of the property 'document': object is null or undefined

$('#Save').click(function () {
    var parent = $(parent.document.body);
    $(parent).find('input#addr_address1').val(addone);
    $(parent).find('input#addr_address2').val(addtwo);
    $(parent).find('input#addr_city').val(city);
    $(parent).find('input#addr_county').val(county);
    $(parent).find('input#addr_postcode').val(postcode);
    $(parent).find('input#addr_country').val(country);
    window.close();            
});

Essentially the variables are set in another function and the values need to be sent back to a set of fields on the parent page.

Any help would be awesome!

Justin Erswell
  • 688
  • 7
  • 42
  • 87
  • `$("#input#addr_address1", window.parent.document);` should work, as noted [here](http://stackoverflow.com/questions/726816/how-to-write-this-in-jquery-window-parent-document-getelementbyidparentprice). – szajmon Sep 12 '11 at 18:59
  • @szajmon thats great thanks however the fields in the parent are not being populated – Justin Erswell Sep 12 '11 at 19:05
  • you have some clarity issues in the above code. you're setting _address2 to addone, for example, and double-jquerifying `parent`... – Dan Davies Brackett Sep 12 '11 at 19:21

1 Answers1

1

In the F12 debugger (I assume you're using IE, by the format of the error message), check the values of parent and parent.document. I bet parent is null. did you mean opener? or top?

Dan Davies Brackett
  • 9,811
  • 2
  • 32
  • 54
  • I am trying to parse the selected values back to the source screen and populate some fields there – Justin Erswell Sep 12 '11 at 19:57
  • when you put a breakpoint on the line reading `var parent = $(parent.document.body);`, and then hover your mouse over `parent` in the source, what value do you see? if it is null, that is your problem. – Dan Davies Brackett Sep 12 '11 at 22:14