If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[RESOLVED] Best way to approach this

Hello everyone, looking for some advice on a problem I am having.

What I am trying to do it allow a user to click a button, which will open a popup with a list of values they can choice from. They need to be able to pick a value, and have it then changed slightly, and sent back to the parent page to populate a text box.

Here's what I've done so far.
When the user click on the button, it passes the ID of the text box to a function, which will open a new window (var child = window.open(...)
This way, i will be able to access the var in the child window. What was happening was the code would continue and pull the value from the child before the user made a choice, so i made a loop to repeat until the window is closed.

do
{
value = child.myVar;
} while (!child.closed)

Which seemed to work fine, how ever, as i tested it in different browsers it would think the script is not responding and crash, or I was getting a "Access denied message".

I started looking into cookies, which would work, but the only problem I am having is that i don't know how to get the script in the parent window to "wait" until the child is closed. My loop method is flawed, can someone please give me an idea on how I can solve this?

You cannot do the loop like you suggeted above as Javascript is a single threaded language and everything would halt indefinitely.

Just a suggestion as I haven't coded this idea personally... but I've seen it done in other sites:

Why not create a fake modal window inside you parent and have it hover over your content (while greying out the background until something has been chosen or a cancel button has been pressed).
Then you can safely run functions and pass data back to fields in your parent window.