www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] Best way to approach this

Hybrid View

  1. #1
    Join Date
    Feb 2012
    Posts
    5

    resolved [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?

  2. #2
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    792
    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.

    Gmail do question windows like that.
    JavaScript: Learn | Validate | Compact | bionoid

  3. #3
    Join Date
    Feb 2012
    Posts
    5
    Thanks, i'll look into modal windows. Will that solve the problem of the code continuing on? That seems to be the issue I am having.

  4. #4
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    792
    As browsers progress, and become more secure, I would say it would be safer to try and do as much as possible without opening external windows or using iframes to interact with.
    JavaScript: Learn | Validate | Compact | bionoid

  5. #5
    Join Date
    Feb 2012
    Posts
    5
    Thanks for the idea on Moral Windows. It Solved the problem.

    It's Worth mentioning that you need to store the value you want to retrun in
    window.returnValue

    Thanks again.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles