Hi,
I have this code for my add to cart on my page and this validation code is just for add to cart and check for "Stock not available". Now I need to insert a code for item order must not be more the the stock in hand. Eg: if the stock in hand is 10 nos then add to cart order quantity cannot be more then 10 nos , need a check code message for this like- "Cannot add more".
Below is the code used presently.
Code:
<script>
function validate()
{
//alert("in");
var id=$("#product_id").val();
var name=$("#hidden_name").val();
var title=$("#hidden_title").val();
var size=$("#size").val();
var color=$("#colorcode").val();
var price=$("#hidden_price").val();
var quantity=$("#quantity").val();
var sizecount=$("#sizecount").val();
var stock=$("#stock").val();
//alert(stock);
var sets=0;
if (parseInt(stock) !=0)
{
if (sizecount !="")
{
if (size =="")
{
alert("Please select the size");
sets=1;
return false;
}
}
if (quantity =="")
{
alert("Please enter the quantity");
return false;
}
if(sets ==0 && quantity !="")
{
var post_url="addtocart.php"
var form_data = $("#productform").serialize();
var request_method = $("#productform").attr("method");
$.ajax({
url : post_url,
type: request_method,
data : form_data
}).done(function(response){ //
//alert(response);
if (response =="success")
{
alert("Product is added");
}
cartupdate();
location.href = window.location
return false;
location.reload();
});
return false;
}
}
else {
alert("Stock is unavailable");
return false;
}
}
function cartupdate()
{
var post_url="https://shoeshineindia.com/minicart.php"
$.ajax({
url : post_url,
type: 'GET'
}).done(function(response){ //
// alert(response);
var res = response.split("~");
$("#cartdata").html(res[0]);
// $("#cartcount").html(res[1]);
$("#cartcount").attr('data-notify', res[1]);
location.href = window.location
return false;
reloadPage: true
});
}
</script>
Can any one help me in this regard.
Gary
CodingForums...
ما را در سایت CodingForums دنبال می کنید
برچسب : نویسنده : codingforums بازدید : 232 تاريخ : چهارشنبه 11 ارديبهشت 1398 ساعت: 22:22