Refreshing parent on post 
June 22nd, 2009, 06:11 PM
| | Newbie | | Join Date: Jun 2009
Posts: 20
| |
I am needing further help following this topic Refresh or close after form submission
The following code should refresh another frame upon submit of the form, but does not. -
<body>
-
<?php
-
if (isset($_POST['submit'])) {
-
?>
-
<script type="text/javascript">
-
window.onload = function() {
-
parent.frameName.document.location.reload();
-
}
-
</script>
-
<?php
-
}
-
?>
-
<select name="choice">
-
<option value="style" selected>Style 1</option>
-
<option value="style2">Style 2</option>
-
</select>
-
<input type="submit" value="Go">
-
</form></div>
-
</body>
-
What is wrong with the code?
| 
June 22nd, 2009, 06:29 PM
|  | Moderator | | Join Date: Nov 2006 Location: Iceland
Posts: 3,701
Provided Answers: 4 | | | re: Refreshing parent on post
Hi.
Well, there is no opening <form> element in this page.
Does it even refresh when you click the submit button?
Add the opening <form> element to it and see if that fixes your problem.
Other than that, I see nothing wrong there. The PHP code should print the <script> if the form is submitted using the submit button.
Although, I can't say for sure about the JavaScript reload there. Haven't worked with frames much.
| 
June 22nd, 2009, 07:43 PM
| | Newbie | | Join Date: Jun 2009
Posts: 20
| | | re: Refreshing parent on post
Oops, i forgot to paste that.
The Javascript runs correctly without the php element, however this causes it to refresh twice uppon page load (orginal load and refresh).
This is why I wanted it to execute when the form is submitied.
| 
June 22nd, 2009, 07:53 PM
| | Newbie | | Join Date: Jun 2009
Posts: 20
| | | re: Refreshing parent on post
Ok, there is a very simple work around.
The Javascript should work without the showing of the re-reloading as long as it is placed at the top of the body.
However, this may not be suitable for all page types as some may not work correctly if the page has been refreshed twice (although most should) e.g. e-commerce scripts, however it works fine for my website.
If anyone actually figures out what is wrong with the above script then I would still like to find out.
Thanks everyone, for your contributions!
| 
June 22nd, 2009, 09:02 PM
| | Newbie | | Join Date: Jun 2009
Posts: 20
| | | re: Refreshing parent on post
Ok, I have found that this does not fix the problem in ie, so I still need to find out what is wrong with the code.
| 
June 22nd, 2009, 09:50 PM
|  | Moderator | | Join Date: Nov 2006 Location: Iceland
Posts: 3,701
Provided Answers: 4 | | | re: Refreshing parent on post
Like I say, there is really nothing wrong with that code.
Unless you count setting the onload event inside the <body> tag (which I would), but that wouldn't really cause any problems.
Have you tried putting your JavaScript in the header and just added/omitted the relocation without actually omitting the entire onload event?
Something like: -
<html>
-
<head>
-
<title>Whatever</title>
-
<script type="text/javascript">
-
window.onload = function()
-
{
-
<?php
-
if(isset($_POST['submit'])) {
-
echo 'parent.frameName.document.location.reload();';
-
}
-
?>
-
}
-
</script>
-
</head>
-
<!-- etc... ->
And are you getting any JavaScript errors?
| 
June 22nd, 2009, 09:55 PM
|  | Moderator | | Join Date: Nov 2006 Location: Iceland
Posts: 3,701
Provided Answers: 4 | | | re: Refreshing parent on post
Additionally, have you tried using the <form> onsubmit event to reload this page before the form is submitted?
That way you wouldn't have to have PHP mess with the JavaScript after it is submitted.
| 
June 22nd, 2009, 11:18 PM
| | Newbie | | Join Date: Jun 2009
Posts: 20
| | | re: Refreshing parent on post
Yes, the form onsubmit does not work. This was one of the first things I tried.
| 
June 22nd, 2009, 11:46 PM
| | Newbie | | Join Date: Jun 2009
Posts: 20
| | | re: Refreshing parent on post
I am not getting any script errors, and it still dosn't refresh the frame uppon submit.
|  | | | | /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 225,662 network members.
|