Refresh or close after form submission | Familiar Sight | | Join Date: Sep 2007
Posts: 221
| | |
I have a page that I want to be refreshed after a user submits a form. I also have another page that I want to be closed after a user submits a form.
How would I go about doing this??
|  | Moderator | | Join Date: May 2007 Location: Munich, Germany
Posts: 4,136
| | | re: Refresh or close after form submission
could you explain that a bit more? what do you mean with closing a page - do you mean closing a window that displays a page? when you submit what happens then - do you call a php script that you control?
kind regards
| | Familiar Sight | | Join Date: Sep 2007
Posts: 221
| | | re: Refresh or close after form submission
I have a popup form that's used to submit comments. When the user clicks the submit button, I'd like the popup window to close once the submission takes place.
|  | Moderator | | Join Date: May 2007 Location: Munich, Germany
Posts: 4,136
| | | re: Refresh or close after form submission
just call a js-function onsubmit of your form that uses window.close()
kind regards
| | Familiar Sight | | Join Date: Sep 2007
Posts: 221
| | | re: Refresh or close after form submission Quote:
Originally Posted by gits just call a js-function onsubmit of your form that uses window.close()
kind regards Excellent, I'll give that a try
| | Familiar Sight | | Join Date: Sep 2007
Posts: 221
| | | re: Refresh or close after form submission
How come if I try to do this:
onSubmit="window.location.reload();" in my form tag it's not submitting the form, it's just refreshing the screen. I want the screen to refresh after the form gets submitted to allow the user to enter a new form without having to jump between screens.
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Refresh or close after form submission
onsubmit is called as soon as the submit button is pressed, not after the submit takes place. Add the refresh to the submitted page instead.
| | Newbie | | Join Date: Jun 2009
Posts: 20
| | | re: Refresh or close after form submission
I have the same problem as I want to make the submit button refresh.
I have 3 frames on my page and need the page to refresh after a submit button is pressed for its changes to take effect (change style sheet)
However using
<input type="submit" onSubmit="window.location.reload();" value="Go">just submits and does not refresh.
I am using the http://php.about.com/od/finishedphp1...s_switcher.htm script.
Does anyone know how to make the button refresh the page as well?
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Refresh or close after form submission
onsubmit is a form event, not an input button event. In any case, that wouldn't work either. I assume the form is in a frame and the form submits to the same frame. What you'd need to do is refresh the whole page after the page has been submitted.
| | Newbie | | Join Date: Jun 2009
Posts: 20
| | | re: Refresh or close after form submission
Yes, I don't want my visitors to have to manualy do that.
I was thinking of putting js into my cookie.php which is what the form is linked to.
But don't know what to add?
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Refresh or close after form submission
You'd need to reference the parent using 'parent' or 'top' and then reload. It is possible to change styles without reloading the page. One other thing: if possible, try to avoid frames.
| | Newbie | | Join Date: Jun 2009
Posts: 20
| | | re: Refresh or close after form submission
I tried targeting it with _Parent but it just loaded the same frame in the frame that was suppost to refresh.
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Refresh or close after form submission
Do you only want to reload one frame or the page which contains the 3 frames?
| | Newbie | | Join Date: Jun 2009
Posts: 20
| | | re: Refresh or close after form submission
just 1 other frame would do, but either. If its possible to reload the whole page then i'd prefer that.
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Refresh or close after form submission
To access the parent (the page containing the frames) and reload it: - parent.location.reload();
You would call this after page load in one of the frames. Is there any particular reason why you're using frames?
| | Newbie | | Join Date: Jun 2009
Posts: 20
| | | re: Refresh or close after form submission
Where would I put that thought.
Its part of the design.
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Refresh or close after form submission
You can put it in the form action page: - window.onload = function() {
-
parent.location.reload();
-
}
| | Newbie | | Join Date: Jun 2009
Posts: 20
| | | re: Refresh or close after form submission
Thank you very much.
Thats the one.. nearly, as this runs the whole page in a loop :P
I just added
So the whole code reads -
window.onload = function() {
-
parent.framename.document.location.reload();
-
}
-
Once again, thank you very much for your help, I do appreciate it. :)
| | Newbie | | Join Date: Jun 2009
Posts: 20
| | | re: Refresh or close after form submission
The only problem I have is that it makes the target frame a bit jumpy when it loads as it has to load twice the first time round (initial load, and refresh).
So is it possible to only run the script when the button is submitted?
I have tried the following but it did not work. -
<input type="submit" value="Go" onSubmit="parent.framename.document.location.reload();">
-
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Refresh or close after form submission
Use PHP code to decide if the code should exist. Only have the JavaScript code run if the form has been submitted, e.g. - <?php
-
if (isset(...)) {
-
?>
-
<script type="text/javascript">
-
...
-
</script>
-
<?php
-
}
-
?>
| | Newbie | | Join Date: Jun 2009
Posts: 20
| | | re: Refresh or close after form submission
It does not refresh when clicked, what have I done wrong?
This is the code in the form frame. -
<?php
-
if (isset($var)) {
-
?>
-
<script type="text/javascript">
-
$var window.onload = function() {
-
parent.frameName.document.location.reload();
-
}
-
</script>
-
<?php
-
}
-
?>
-
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: Refresh or close after form submission
No, it doesn't quite work like that. You need to replace $var with the posted variable in PHP, e.g. $_POST['submit']. Also remove $var on line 5. If you have any more problems on that front, ask in the PHP forum.
|  | Similar JavaScript / Ajax / DHTML bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,501 network members.
|