Connecting Tech Pros Worldwide Forums | Help | Site Map

Refreshing parent on post

Newbie
 
Join Date: Jun 2009
Posts: 20
#1: Jun 22 '09
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.

Expand|Select|Wrap|Line Numbers
  1. <body>
  2. <?php  
  3.     if (isset($_POST['submit'])) { 
  4. ?> 
  5. <script type="text/javascript"> 
  6. window.onload = function() {  
  7.     parent.frameName.document.location.reload();  
  8. }   
  9. </script> 
  10. <?php 
  11.     } 
  12. ?> 
  13. <select name="choice">
  14. <option value="style" selected>Style 1</option>
  15. <option value="style2">Style 2</option>
  16. </select>
  17. <input type="submit" value="Go">
  18. </form></div>
  19. </body>
  20.  
What is wrong with the code?

Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,754
#2: Jun 22 '09

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.
Newbie
 
Join Date: Jun 2009
Posts: 20
#3: Jun 22 '09

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.
Newbie
 
Join Date: Jun 2009
Posts: 20
#4: Jun 22 '09

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!
Newbie
 
Join Date: Jun 2009
Posts: 20
#5: Jun 22 '09

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.
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,754
#6: Jun 22 '09

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:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2.   <head>
  3.     <title>Whatever</title>
  4.     <script type="text/javascript">
  5.     window.onload = function()
  6.     {
  7.       <?php
  8.         if(isset($_POST['submit'])) {
  9.           echo 'parent.frameName.document.location.reload();';
  10.         }
  11.       ?>
  12.     }
  13.     </script>
  14.   </head>
  15.   <!-- etc... ->
And are you getting any JavaScript errors?
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,754
#7: Jun 22 '09

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.
Newbie
 
Join Date: Jun 2009
Posts: 20
#8: Jun 22 '09

re: Refreshing parent on post


Yes, the form onsubmit does not work. This was one of the first things I tried.
Newbie
 
Join Date: Jun 2009
Posts: 20
#9: Jun 22 '09

re: Refreshing parent on post


I am not getting any script errors, and it still dosn't refresh the frame uppon submit.
Reply