473,386 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Accessing dynamically generated fields from a child popup

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

Jun 23 '06 #1
1 2566
Well I found out what was wrong so I decided to post the answer for
anyone else. If all else fails make sure you aren't confusing the
browser into thinking you are trying to access something under another
domain. Basically, my development server is my workstation, and I
access the site using a domain that is in my hosts file that points to
localhost. Apparently, this caused a problem, making the browser think
that the parent and child windows were not on the same domain. I
copied the code to the production machine, which has a real domain, and
everything worked fine. Hopefully this will keep someone else from
pulling their hair out for days over something like this.

If you are having trouble accessing objects when dealing with parent
child relationships, first make sure the browser doesn't think you are
trying to access across different domains.

Adam
ad**********@gmail.com wrote:
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


Jun 28 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: HarveyB | last post by:
I would like to generate non-modal popup windows from ASP.Net code-behind. I have tried using Client Side scripting like "function Test(){ window.open('test.htm',_blank,...
1
by: Alan | last post by:
I am trying to use javascript modal popup windows (window.createModalWindow) to display HTML forms. The problem is - the form size and content varies. The same entry form, under different...
4
by: EmmettPower | last post by:
Hi, I have a form which includes a field 'number'. When 'number' is changed additional fields ('item_0', etc) are generated on the form using 'onchange'. I want to validate the form using...
2
by: Sethos | last post by:
I am sure that this has been covered, hashed, and rehashed, but a search on the group did not produce the answer, so forgive me if this seems like a "newbie" type question... Besically, I have a...
5
by: stellstarin | last post by:
I have a html where fields are created and added dynamically on the client side. I use the AppendChild() call to create fields dynamically. On submit i try to get the value for all the...
5
by: midnight_use_only | last post by:
hi all, quick question, how do you submit a form to a parent window from a child popup window? i have the following and all online documentation *suggests* that it should work but it does NOT: ...
1
verbatim
by: verbatim | last post by:
with the following page, the dynamically generated fields are not recognized when i try to submit the form, or add more elements. when i hit my submit button, the address bar has only x1 - x5 in...
5
by: TurboRogue | last post by:
So here's the basic premise: I have an html page with a bunch of pictures (pic.html). All of the images are thumbnails of larger photos. I also have another html page which is a pop-up window...
4
by: Lewis Holmes | last post by:
Hi I have the following situation in one of my asp.net pages. The user can add multiple table rows to a form by selecting a button. These rows can contain asp.net controls. When this button is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.