$(document).ready(function() {
var newcount = $(".total_number").data("products_total_number")
var allprice = $(".fullprice").data("her")
$("#price").html(allprice);
var btnn = $("#submit_btn");
var form = $(".formselect");
form.on('submit', function(e) {
e.preventDefault();
var product_id = $(".info").data("product_id");
var product_name = $(".info").data("product_name");
var price = $(".info").data("product_price");
var quantity = $("#sel1").val();
var full_price_per_item = (price * quantity)
newprice = allprice + (price * quantity );
allprice = newprice
newcount++;
$(".count").html(newcount);
var data = {};
data.product_id = product_id;
data.product_name = product_name;
data.product_price = price;
data.product_quantity = quantity;
data.product_newprice = newprice;
data.product_newcount = newcount;
data.product_allprice = allprice;
var csrf_token = $('.formselect [name="csrfmiddlewaretoken"]').val();
data["csrfmiddlewaretoken"] = csrf_token;
var url = form.attr("action");
console.log(data)
$.ajax({
url: url,
type: 'POST',
data: data,
cache: true,
success: function(data){
console.log("OK");
console.log(data.products)
$.each(data.products, function(){
$(".basket-item ul").append('<li class="del">' + '<span class="goods">Goods:' + product_name + '</span>'
+ '<span class="quantity"> Quantity:' + '<span class="count_of_quantity">' + quantity + '</span>' + '</span>'
+ '<a href="#" class="deleteitem">X</a>' + '<span class="hidden del_price">'+ full_price_per_item + '</span>' + "</li>")
})
},
error: function(data){
console.log("ERROR")
}
});
$(".liii").mouseover(function(e){
e.preventDefault();
$(this).addClass("cartcolor");
});
$(".liii").mouseout(function(e){
e.preventDefault();
$(this).removeClass("cartcolor");
} );
$(".basket-container").mouseover(function(e){
e.preventDefault();
$(".basket-item").removeClass("hidden");
$("#submit_btn").removeClass("hidden");
});
$(".basket-container").mouseout(function(e){
e.preventDefault();
$(".basket-item").addClass("hidden");
$("#submit_btn").addClass("hidden");
});
$(document).on('click', '.deleteitem', function(e){
e.preventDefault();
var cost = $(this).closest('li').find(".del_price").html();
$(this).closest('li').remove();
var allprice = $(".fullprice").data("her")
console.log(allprice)
newprice = allprice - cost ;
allprice = newprice
newcount--;
$(".count").html(newcount);
$("#price").html(newprice);
});
});
});в твою функцию form
$(document).ready(function() {
var newcount = $(".total_number").data("products_total_number")
var allprice = $(".fullprice").data("her")
$("#price").html(allprice);
var btnn = $("#submit_btn");
var form = $(".formselect");
form.on('submit', function(e) {
e.preventDefault();
var product_id = $(".info").data("product_id");
var product_name = $(".info").data("product_name");
var price = $(".info").data("product_price");
var quantity = $("#sel1").val();
var full_price_per_item = (price * quantity)
newprice = allprice + (price * quantity );
allprice = newprice
newcount++;
$(".count").html(newcount);
var data = {};
data.product_id = product_id;
data.product_name = product_name;
data.product_price = price;
data.product_quantity = quantity;
data.product_newprice = newprice;
data.product_newcount = newcount;
data.product_allprice = allprice;
var csrf_token = $('.formselect [name="csrfmiddlewaretoken"]').val();
data["csrfmiddlewaretoken"] = csrf_token;
var url = form.attr("action");
console.log(data)
$.ajax({
url: url,
type: 'POST',
data: data,
cache: true,
success: function(data){
console.log("OK");
console.log(data.products)
$.each(data.products, function(){
$(".basket-item ul").append('<li class="del">' + '<span class="goods">Goods:' + product_name + '</span>'
+ '<span class="quantity"> Quantity:' + '<span class="count_of_quantity">' + quantity + '</span>' + '</span>'
+ '<a href="#" class="deleteitem">X</a>' + '<span class="hidden del_price">'+ full_price_per_item + '</span>' + "</li>")
})
},
error: function(data){
console.log("ERROR")
}
});
});
$(".liii").mouseover(function(e){
e.preventDefault();
$(this).addClass("cartcolor");
});
$(".liii").mouseout(function(e){
e.preventDefault();
$(this).removeClass("cartcolor");
} );
$(".basket-container").mouseover(function(e){
e.preventDefault();
$(".basket-item").removeClass("hidden");
$("#submit_btn").removeClass("hidden");
});
$(".basket-container").mouseout(function(e){
e.preventDefault();
$(".basket-item").addClass("hidden");
$("#submit_btn").addClass("hidden");
});
$(document).on('click', '.deleteitem', function(e){
e.preventDefault();
var cost = $(this).closest('li').find(".del_price").html();
$(this).closest('li').remove();
var allprice = $(".fullprice").data("her")
console.log(allprice)
newprice = allprice - cost ;
allprice = newprice;
newcount--;
$(".count").html(newcount);
$("#price").html(newprice);
});
});
$(document).ready(function() {
var newcount = $(".total_number").data("products_total_number");
var allprice = $(".fullprice").data("her");
$("#price").html(allprice);
var btnn = $("#submit_btn");
var form = $(".formselect");
form.on('submit', function(e) {
e.preventDefault();
var product_id = $(".info").data("product_id");
var product_name = $(".info").data("product_name");
var price = $(".info").data("product_price");
var quantity = $("#sel1").val();
var full_price_per_item = (price * quantity);
newprice = allprice + (price * quantity);
allprice = newprice;
newcount++;
$(".count").html(newcount);
var data = {};
data.product_id = product_id;
data.product_name = product_name;
data.product_price = price;
data.product_quantity = quantity;
data.product_newprice = newprice;
data.product_newcount = newcount;
data.product_allprice = allprice;
var csrf_token = $('.formselect [name="csrfmiddlewaretoken"]').val();
data["csrfmiddlewaretoken"] = csrf_token;
var url = form.attr("action");
console.log(data);
$.ajax({
url: url,
type: 'POST',
data: data,
cache: true,
success: function(data) {
console.log("OK");
console.log(data.products)
$.each(data.products, function() {
$(".basket-item ul").append('<li class="del">' + '<span class="goods">Goods:' + product_name + '</span>' +
'<span class="quantity"> Quantity:' + '<span class="count_of_quantity">' + quantity + '</span>' + '</span>' +
'<a href="#" class="deleteitem">X</a>' + '<span class="hidden del_price">' + full_price_per_item + '</span>' + "</li>")
})
},
error: function(data) {
console.log("ERROR");
}
});
$(".liii").mouseover(function(e) {
e.preventDefault();
$(this).addClass("cartcolor");
});
$(".liii").mouseout(function(e) {
e.preventDefault();
$(this).removeClass("cartcolor");
});
$(".basket-container").mouseover(function(e) {
e.preventDefault();
$(".basket-item").removeClass("hidden");
$("#submit_btn").removeClass("hidden");
});
$(".basket-container").mouseout(function(e) {
e.preventDefault();
$(".basket-item").addClass("hidden");
$("#submit_btn").addClass("hidden");
});
$(document).on('click', '.deleteitem', function(e) {
e.preventDefault();
var cost = $(this).closest('li').find(".del_price").html();
$(this).closest('li').remove();
var allprice = $(".fullprice").data("her");
console.log(allprice);
newprice = allprice - cost;
allprice = newprice;
newcount--;
$(".count").html(newcount);
$("#price").html(newprice);
});
});
});