سلام والله موندم چرا آخه این اینطوری میکنه کمکم کنید مقداری که میزنم به وقتی زیاد میکنم 5 رو چهار نشون میده یعنی یکی کم جالب اینه وقتی کم میکنم بفرض رو 5 هستم میزم تعداد بشه چهار حالا مقدار VALUE میشه 5 جالب چهار توش ثبت میشه ممنون کمک کنید دو روزه توش موندم
کد اچ تی ام ال
<div class="offcanvas-required-number-cart">
<div class="required-number before">
<div class="quantity">
<input type="number" min="1" max="100" step="1" value="0" id="input-quantity">
<div class="quantity-nav">
<div class="quantity-button quantity-up" onclick="addToCart({{$product->id}});">+</div>
<div class="quantity-button quantity-down" onclick="addToCart({{$product->id}});" >-</div>
</div>
<div class="quantity-nav">
</div>
</div>
</div>
جاوا
function addToCart(productId)
{
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var quantity=1;
if($('#input-quantity').length){
quantity=document.getElementById('input-quantity').value;
console.log(quantity);
console.log(document.getElementById('input-quantity').value);
}
$.ajax({
type: 'POST',
url: "/cart/"+productId,
data:
{
quantity: quantity
},
success:function (data) {
$('#total_items').text(data.cart.total_items);
$('#total_amount').text(data.cart.total_amount);
if(!$('#cart-row-'+ productId).length){
var cost_with_discount=data.cart[productId]['cost_with_discount'];
var product=data.cart[productId]['product'];
var productQty = data.cart[productId]['quantity'];
if(product.cost_with_discount==product.cost)
{
$('#cart-table-body:last-child').append(
' <div class="offcanvas-product-box cart-item" id="cart-row-'+ product.id +'">\n' +
'<!-- remove-product -->\n' +
'<button type="submit" class="offcanvas-product-box_delete remove-from-cart" onclick="removeFromCart('+ product.id +')">\n' +
'<i class="mdi mdi-close"></i>\n' +
' </button>\n' +
'<!--product img-->\n' +
'<div class="offcanvas-product-box_image">\n' +
'<img src="'+ product.image_path +'" style="width: 80px" alt="'+ product.name +'">\n' +
' </div>\n' +
'<div class="offcanvas-product-box-content float-right">\n' +
' <!--product title-->\n' +
'<span class="offcanvas-product-box-title text-truncate">'+ product.name +'</span>\n' +
'<div class="justify-content-between">\n' +
'<div class="offcanvas-product-box-price">\n' +
'<div class="offcanvas-product-box-price-value">'+cost_with_discount * productQty+'\n' +
'<span class="offcanvas-product-box-price-currency">تومان</span>\n' +
'</div>\n' +
'</div>\n' +
'\n' +
'<div class="offcanvas-required-number-cart">\n' +
'<div class="required-number before">\n' +
'<div class="quantity">\n' +
'<input type="text" min="1" max="100" name="quantity" step="1" value="1" >\n' +
'<div class="quantity-nav">\n' +
'</div>\n' +
'</div>\n' +
' </div>\n' +
'\n' +
'</div>\n' +
'</div>\n' +
'</div>\n' +
' </div>\n'
);
}
else{
$('#cart-table-body:last-child').append(
' <div class="offcanvas-product-box cart-item" id="cart-row-'+ product.id +'">\n' +
'<!-- remove-product -->\n' +
'<button type="submit" class="offcanvas-product-box_delete remove-from-cart" onclick="removeFromCart('+ product.id +')">\n' +
'<i class="mdi mdi-close"></i>\n' +
' </button>\n' +
'<!--product img-->\n' +
'<div class="offcanvas-product-box_image">\n' +
'<img src="'+ product.image_path +'" style="width: 80px" alt="'+ product.name +'">\n' +
' </div>\n' +
'<div class="offcanvas-product-box-content float-right">\n' +
' <!--product title-->\n' +
'<span class="offcanvas-product-box-title text-truncate">'+ product.name +'</span>\n' +
'<div class="justify-content-between">\n' +
'<div class="offcanvas-product-box-price">\n' +
'<del>'+product.cost+'</del>\n' +
'<div class="offcanvas-product-box-price-value">'+cost_with_discount * productQty+'\n' +
'<span class="offcanvas-product-box-price-currency">تومان</span>\n' +
'</div>\n' +
'</div>\n' +
'\n' +
'<div class="offcanvas-required-number-cart">\n' +
'<div class="required-number before">\n' +
'<div class="quantity">\n' +
'<input type="text" min="1" max="100" name="quantity" step="1" value="1" >\n' +
'<div class="quantity-nav">\n' +
'</div>\n' +
'</div>\n' +
' </div>\n' +
'\n' +
'</div>\n' +
'</div>\n' +
'</div>\n' +
' </div>\n'
);
}
}
}
});
}
در کل قسمت INPUT هر چی نشون میده وقتی زیاد میکنم تو جاوا یکی کم نشون میده و وقتی کم میکنم تو جاوا یکی زیاد
شاید پاسخ شما همینجا باشد