Welcome to the MacNN Forums.

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.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Javascript Help

Javascript Help
Thread Tools
Mac Elite
Join Date: Jan 2001
Status: Offline
Reply With Quote
Jun 8, 2004, 03:33 PM
 
Hi,

I have a website where you edit entries. When you click edit, a popup window appears where you can edit it, and click a save button. Does anyone know how to make it submit the form, then close the popup, and then refresh the main website with the entries?

Thanks!
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Jun 8, 2004, 05:42 PM
 
Hummm.. Taking this from first impressions (you've been a wee bit vague), I'd say that this can't be done with javascript. Javascript can't save things to your server (well, it can, with XMLHttpRequest's save property, but that hasn't been implemented yet, as far as I've seen), so you can modify the original page, but you can't save the changes to your server with just javascript.

However, it is very possible to have a pop-up window convey changed info to the page that 'popped' it open... In the opened page, just either save the info changed as cookies that the main page looks at, or use the window.opener method to change variables or elements' contents...

If you have an exact spec for what you need, I think we can tackle it

Oh, edit:

closing the pop-up window is as simple as using window.close(). My qualm is wether or not changes are to be permanent to the site (unlikely), to be for the user every time they visit or to be just viewed once they've changed them, and never again...
(Last edited by Black Book; Jun 9, 2004 at 06:00 AM. )
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
timmerk  (op)
Mac Elite
Join Date: Jan 2001
Status: Offline
Reply With Quote
Jun 8, 2004, 05:49 PM
 
Hi,

Thanks. No, I meant when the user clicks the Save button, it could run a Javascript to submit the form (I have seen this done before), and then close the window. Then it would just refresh the other page.

Thanks
     
Occasionally Useful
Join Date: Jun 2001
Location: Liverpool, UK
Status: Offline
Reply With Quote
Jun 8, 2004, 06:19 PM
 
Originally posted by Black Book:
However, it is very possible to have a pop-up window convey changed info to the page that 'pooped' it open... In the opened page, just either save the info changed as cookies that the main page looks at, or use the window.opener method to change variables or elements' contents...
phpBB's admin section does something like this. when you need to find a username, a window opens, you search in that window, and then selecting the name closes the window and populates the relevant field in the parent window. here's the code from that poopy window
Code:
<script language="javascript" type="text/javascript"> <!-- function refresh_username(selected_username) { opener.document.forms['post'].username.value = selected_username; opener.focus(); window.close(); } //--> </script>
"Have sharp knives. Be creative. Cook to music" ~ maxelson
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Jun 9, 2004, 06:27 AM
 
Originally posted by timmerk:
Hi,

Thanks. No, I meant when the user clicks the Save button, it could run a Javascript to submit the form (I have seen this done before), and then close the window. Then it would just refresh the other page.

Thanks
Javascript to submit the form:
document.forms[0].submit();

To refresh the other page:

window.opener.location.reload();

To close the opened window:
window.close();

Chuck all that in a function that the save button calls on click and it should work.

I'm not sure what the opener page is doing - is the form in the opened page changing details in a SQL table or something, and your opener page refreshes to get the changes?
If so, you might want to put a slight delay into the reloading of the opener page...
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Jun 9, 2004, 07:12 AM
 
Originally posted by timmerk:
Hi,

Thanks. No, I meant when the user clicks the Save button, it could run a Javascript to submit the form (I have seen this done before), and then close the window. Then it would just refresh the other page.

Thanks
Javascript to submit the form:
document.forms[0].submit();

To refresh the other page:

window.opener.location.reload();

To close the opened window:
window.close();

Chuck all that in a function that the save button calls on click and it should work.

I'm not sure what the opener page is doing - is the form in the opened page changing details in a SQL table or something, and your opener page refreshes to get the changes?
If so, you might want to put a slight delay into the reloading of the opener page...
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
Grizzled Veteran
Join Date: Nov 2003
Location: Hebburn, UK
Status: Offline
Reply With Quote
Jun 9, 2004, 08:02 AM
 
Hmm, so how come there's two posts of mine above this one (one's a double post) but they aren't showing up in the threads list... I also can't edit them or anything. Weird.

Well, not that weird, since the forums were going a bit mental when I posted the above...
Just who are Britain? What do they? Who is them? And why?

Formerly Black Book
     
timmerk  (op)
Mac Elite
Join Date: Jan 2001
Status: Offline
Reply With Quote
Jun 9, 2004, 01:43 PM
 
It works, thanks!
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:34 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2