#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    13
    Rep Power
    0

    Issues with forms


    I have a form to a shopping cart that I am developing, that adds a product to the cart using standard HTML forms. To give some feedback I open a popup window using onsubmit, and opening a new window on top with the following code
    Code:
    function display_alert(p,c)
    	{
    	var h=260;
    	var w=380;
    	var left = (screen.width/2)-(w/2);
    	var top = (screen.height/2)-(h/2);
    	var targetWin = window.open("./alert.php?prod="+p+"&coll="+c, "_blank", "location=no, status=no, toolbar=no, menubar=no, directories=no, width="+w+", height="+h+", top="+top+", left="+left);
    	}
    Variable P is the product ID, and C is the collection (category) ID.

    I also want to pass the quantity of products ordered to this function, HOWEVER the quantity is an HTML text box within the same form, called as so:

    Code:
    <input type="text" name="cart_quantity" value="0" maxlength="6" size="4" />
    I have tried to use the PhP $_POST to read the data from the form, but it won't read the data - presumably as I am not directly submitting the data from the form to the alert.php file.

    So the question is: how can I get this cart_quantity variable either into the URL data or passed to the alert.php file?

    Any help would be appreciated.
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,110
    Rep Power
    119
    You mean something like this:

    [code=JavaScript]
    function display_alert(p,c)
    {
    var h=260;
    var w=380;
    var left = (screen.width/2)-(w/2);
    var top = (screen.height/2)-(h/2);
    var quantity = document.getElementById("cq").value;
    var targetWin = window.open("./alert.php?prod="+p+"&coll="+c+"&quantity="+quantity, "_blank", "location=no, status=no, toolbar=no, menubar=no, directories=no, width="+w+", height="+h+", top="+top+", left="+left);
    }
    [/code]

    [code=HTML]<form onsubmit="display_alert('0123','3210')">
    <input id="cq" type="text" name="cart_quantity" value="0" maxlength="6" size="4" />
    <input type="submit"/>
    </form>[/code]

IMN logo majestic logo threadwatch logo seochat tools logo