help with code- php

Discussion in 'Web Design and Development' started by captainmeowtron, Jul 20, 2009.

  1. captainmeowtron macrumors member

    Dec 1, 2008
    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" / >

  2. whatsgooddan macrumors member

    Apr 6, 2009
    NY, USA
    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.
  3. Darth.Titan macrumors 68030


    Oct 31, 2007
    Austin, TX
  4. captainmeowtron thread starter macrumors member

    Dec 1, 2008
    I don't know. I guess that's my question- should the onclick event be in a separate part, and is that the problem?
  5. angelwatt Moderator emeritus


    Aug 16, 2005
    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.
  6. captainmeowtron thread starter macrumors member

    Dec 1, 2008
    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.
    <STYLE type="text/css">
    A { text-decoration:none }
    <body bgcolor="#000000" TEXT="000000" body link="#000000" vlink="#000000" alink="#000000">
    <table border="0" bordercolor="" style="background-color:#000000" width="100%" cellpadding="" cellspacing="">
    <td><img src="1.jpg"></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" / >

Share This Page