 |
 |
Javascript Help
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Status:
Offline
|
|
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
|
|
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
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Status:
Offline
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Jan 2001
Status:
Offline
|
|
|
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|