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 function changeParentLocation() { document.frm1.submit(); self.parent.location.href = 'cart.php'; return true; } HTML: and this is the HTML to call this function <input type="button" name="Submit" value="Update Price" onclick="return update_price();" /> HTML: It's not working. What's wrong I,m doing here?
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.
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.
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?
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
The output from the server (in the iframe, after the form processes) should include a line of script such as: <script type="text/javascript"><!-- parent.location = "cart.php"; // --> </script> Code (markup): 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.