NewbieQ: How do I refresh view after return from popup w

AJAX seems like a good option here. But if you don't want to get into that and don't mind the whole page being refreshed you could also try something like this:

- Add a hidden field to your form called "organisation_added" which is set to false by default. - Then when an organisation is added, use JavaScript to set "organisation_added" to true and post the form. - Then with Ruby, if params['organisation_added'] is set to true create a person object using the data that has already been entered (@person = Person.new(params[:person]) ), and re-render the form. - params['organisation_added'] == false means the user posted the form manually, so in that case you can save the person to your DB.

Good luck!

Hi

- Then when an organisation is added, use JavaScript to set "organisation_added" to true and post the form.    How to do this bit?

In particular how to use javascript from the popup to reference the page it was popped up from. Also how to set the field and post the form whilst not loosing any of the data already entered?

In my case I want to let the user enter som Lat/Lon position data, OR for convenience popup a google maps object and have it fill in the details in the original form when the user clicks on a location. I don't feel that I need to post the form, just figure out how to reference back from the popped up page back to the original page?

Cheers

Ed W

In Javascript window.opener is your reference to the parent window, i.e. the window it was popped up from. Example:

In your main page where the form exists: <input type="hidden" id="person_haircolour" name="person[haircolour]" value="#FFFFFF"/><!-- This guy must be an albino! lol -->

In the pop-up page: <input type="button" onclick="window.opener.getElementById('person_haircolour').value = selectedColour; window.close();" />