简体   繁体   中英

asp.net shopping cart update quantity in cookie

in shopping cart web page i have this list view to show items in cart:

 <asp:ListView ID="List" runat="server" DataKeyNames="ID">


          <table class="tbl">
                    <tr>
                      <td class="one">
                        <h4><%# Eval("ID")%></h4>
                      </td>
                      <td class="two">
                         <h4><%# Eval("Name")%></h4>
                      </td>
                      <td class="fone"><%# Eval("Total")%></td>

                      <td>
                          <asp:DropDownList runat="server" CssClass='drop' SelectedValue='<%# Eval("Qty")%>'>
                          <asp:ListItem value="1">1</asp:ListItem>
                          <asp:ListItem value="2">2</asp:ListItem>
                          <asp:ListItem value="3">3</asp:ListItem>
                          <asp:ListItem value="4">4</asp:ListItem>
                         </asp:DropDownList>
                      </td> 

                      <td class="ffour"><%# Eval("Price")%></td>
                    </tr>

            </table>

items retrieve from cookie .when user add item to cart, item added to this listview . i have written jquery code to, when user change quantity of one item , totalprice automatically has been changed .

 $('.drop').on('change', function () {
               var tr = $(this).closest('tr');
               var price = $(tr).find('.ffour').html();
               $(tr).find('.fone').html(price * $(this).val());
           });

how to do when user change quantity , qty in cookie changes too?for example , when user change quantity of first row from 1 to 2 , in website cookie , qty changes from 1 to 2 .

name of cookie is 'SiteCookie' . and has Qty for quantity of products.

First of all Take this js for Cookies and then

       $('.drop').on('change', function () {
           $.cookie("qty",$(this).closest('tr'))
           var price = $(tr).find('.ffour').html();
           $(tr).find('.fone').html(price * $.cookie("qty"));
       });

On page load as well u can call cookie... if cookie has value then perform this

      $(tr).find('.fone').html(price * $.cookie("qty"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM