1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Change Parent Location on IFrame submit

Discussion in 'JavaScript' started by greatlogix, Mar 6, 2008.

  1. #1
    I am using IFrame to display a form. On submitting Form i want to change URL of parent window.

    Here is the javascript I am using
    HTML:
    1.  
    2. function changeParentLocation() {
    3.     document.frm1.submit();
    4.     self.parent.location.href = 'cart.php';
    5.     return true;
    6. }
    7.  
    and this is the HTML to call this function

    HTML:
    1. <input type="button" name="Submit" value="Update Price" onclick="return update_price();" />
    It's not working. What's wrong I,m doing here?
     
    greatlogix, Mar 6, 2008 IP
  2. vpguy

    vpguy Guest

    Messages:
    275
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    For starters, the name of the function being called from the submit button ("update_price") is not the same as the function specified in the Javascript ("changeParentLocation").

    But that's not your only problem. If you try to change the parent location immediately after the user clicks the submit button, then the iframe itself no longer exists because it was a child of the parent, which means that the form would never end up being submitted to the server.

    Without more details, this setup seems a bit messy. You should consider restructuring it without using frames.
     
    vpguy, Mar 7, 2008 IP
  3. greatlogix

    greatlogix Active Member

    Messages:
    663
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #3
    Silly me. I pasted wrong code above.

    Following the correct code
    <input type="button" name="Submit" value="Update Price" onclick="changeParentLocation();" />

    On clicking this button I get form submitted and next page (where form is submitted) loads in IFrame coz Submit button and Javascript function is in IFrame.

    This line is not working
    self.parent.location.href = 'cart.php';

    On form submit in IFrame I want to change location of parent window.
     
    greatlogix, Mar 8, 2008 IP
  4. vpguy

    vpguy Guest

    Messages:
    275
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    But do you want the parent location to change after the form processes and receives output back from the server, or before the form processes?
     
    vpguy, Mar 8, 2008 IP
    greatlogix likes this.
  5. greatlogix

    greatlogix Active Member

    Messages:
    663
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #5
    of course I want to change parent location after the form submit.

    Are you trying to say that I should change parent on the page where form is submitted and execute this line( self.parent.location.href = 'cart.php';) after server response. hmmm..... not a bad idea. I will try it....

    If there is something else in your mind please share. Rep Added
     
    greatlogix, Mar 8, 2008 IP
  6. vpguy

    vpguy Guest

    Messages:
    275
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    The output from the server (in the iframe, after the form processes) should include a line of script such as:

    Code (Text):
    1.  
    2. <script type="text/javascript"><!--
    3. parent.location = "cart.php";
    4. // -->
    5. </script>
    6.  
    You should remove that corresponding line from the update_price() or changeParentLocation() function.

    And keep in mind that when the parent location changes, the iframe will be destroyed. A new one might be created if cart.php contains an iframe, but it won't be the same instance.
     
    vpguy, Mar 8, 2008 IP
  7. greatlogix

    greatlogix Active Member

    Messages:
    663
    Likes Received:
    13
    Best Answers:
    1
    Trophy Points:
    85
    #7
    Thanks I will try it....
     
    greatlogix, Mar 8, 2008 IP