0

I have a dropped down button and when chosen will be save to cookie. I have to save in cookie so that I can redeem in the checkout page. Have this so far but cant save them to the cookies:

    function storeValues(form)
    {
    setCookie("product1",form.product1.value);
            return true;
    }

    </script>
     <ul>
     <li><img src="images/1.jpg" alt="Product1" />
     100% Pure Glutamine Powder</br>
    Ultimate Recovery Fuel!*</br>
    Supports Recovery From Workouts!*</br>


    <form name="myform" action="checkout.html" method="POST">
    <div align="center">
    $12.99</br>
    Select Quantity
    <select name="product1" onchange="return storeValues(this);">>
    <option value="1">0</option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    </select>
    </div>
    </li>
4

1 回答 1

0

js中没有setCookie函数。您可以使用 jQuery cookie 库或创建自己的设置 cookie 函数。

使用这样的东西(取自http://www.quirksmode.org/js/cookies.html

function setCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
于 2013-04-01T21:12:19.553 回答