I have a page with some form elements that are dynamically generated.
They are inserted into the dom by first cloning a node, changing the
values like name, and then inserted with insertBefore().
When a field gets added, a link that opens a popup window is next to
it. The popup is opened and has the name of the parent element it
should change in it. The user can use the popup to get a list of
results. In the results I would like them to be able to click on the
result and it set the value of of the element to the value of the
result.
If I have one of the fields on the page as plain html and not dynamic,
everything works. When I try to access one of the dynamic fields from
the child, it's null. I can access the dynamic field from the parent
no problem, but not from the child.
This function is in the head of the parent window and is called from
the child:
function setValue(elementId, val)
{
var el = document.getElementById(elementId);
el.value = val;
}
The child calls this function like this:
window.opener.setValue('myElementId', 'value');
I've also tried setting the value like this from the child:
window.opener.document.forms[formName].elements[elementName].value =
val;
And this:
var el = window.opener.document.getElementById(elementName) ;
el.value = val;
Again, whenever I run the code on an element that was not dynamically
inserted into the dom, it works fine. It only has trouble on elements
that were put in dynamically.
If anybody has any suggestions, they would be greatly appreciated.
Adam