Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

captainmeowtron

macrumors member
Original poster
Dec 1, 2008
43
0
I have a form, and what I'm trying to do is post info to the form using
<form method="post" action="ShoppingCart.php">
and a submit button. I also want to have the window close and return the user to the original parent window (the form is in a popup.)
I've tried
onclick="window.opener.location.href='ShoppingCart.php'; window.close();"
and the problem seems to be that assigning all three actions to the button, sometimes it posts to the form first and then closes and returns, and sometimes it does not (sometimes it closes and returns without posting to the cart.)
I also tried onRelease, but nothing happened. Here's what my code looks like now, can anyone help me out?
<form method="post" action="ShoppingCart.php" onclick="window.opener.location.href='ShoppingCart.php'; window.close();">
[item description]
<input type="submit" name="Submit" value="Add To Cart" / >

</form>
 
Can you kill the popup on "shoppingcart.php" instead of the page with the form?

Or, maybe you can avoid the popup all together. I know that strict xhtml doesn't like target="_blank". With people using iPhones and various types of browsers, sometimes popups can be a real pain.

Of course, there are also people with popup blockers who don't know that they have to hold CTRL while clicking, or do whatever they need to do to disable their blocker.
 
I don't know. I guess that's my question- should the onclick event be in a separate part, and is that the problem?
 
I don't know. I guess that's my question- should the onclick event be in a separate part, and is that the problem?

Attaching an onclick onto the form will fire any time a visitor clicks any part of that form (labels, open space, form fields, etc.), not just the submit button. That's why it's a problem. Using onsubmit would be a better choice.
 
Here's what I've got now, and it's still not working. What happens is that the popup closes and returns to the specified url, but nothing is adding to the cart.
<html>
<head>
<title>jewelery</title>
<STYLE type="text/css">
<!--
A { text-decoration:none }
-->
</STYLE>
</head>
<body bgcolor="#000000" TEXT="000000" body link="#000000" vlink="#000000" alink="#000000">
<table border="0" bordercolor="" style="background-color:#000000" width="100%" cellpadding="" cellspacing="">
<tr>
<td><img src="1.jpg"></td>

<td>     </td>
<td>
<form method="post" action="ShoppingCart.php" onsubmit="window.opener.location.href='ShoppingCart.php'; window.close();">
[item description]
<input name="cmd" type="hidden" id="cmd" value="1" />
<input type="submit" name="Submit" value="Add To Cart" / >
</td>
</tr>
</table>
</body>
</html>
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.