Refreshing parent on post

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • htmlnoob112233
    New Member
    • Jun 2009
    • 20

    Refreshing parent on post

    I am needing further help following this topic http://bytes.com/topic/javascript/an...on#post3493808

    The following code should refresh another frame upon submit of the form, but does not.

    Code:
    <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?
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    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.

    Comment

    • htmlnoob112233
      New Member
      • Jun 2009
      • 20

      #3
      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.

      Comment

      • htmlnoob112233
        New Member
        • Jun 2009
        • 20

        #4
        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!

        Comment

        • htmlnoob112233
          New Member
          • Jun 2009
          • 20

          #5
          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.

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            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:
            [code=php]
            <html>
            <head>
            <title>Whatever </title>
            <script type="text/javascript">
            window.onload = function()
            {
            <?php
            if(isset($_POST['submit'])) {
            echo 'parent.frameNa me.document.loc ation.reload(); ';
            }
            ?>
            }
            </script>
            </head>
            <!-- etc... ->[/code]

            And are you getting any JavaScript errors?

            Comment

            • Atli
              Recognized Expert Expert
              • Nov 2006
              • 5062

              #7
              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.

              Comment

              • htmlnoob112233
                New Member
                • Jun 2009
                • 20

                #8
                Yes, the form onsubmit does not work. This was one of the first things I tried.

                Comment

                • htmlnoob112233
                  New Member
                  • Jun 2009
                  • 20

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

                  Comment

                  Working...