This question already has an answer here:
I have the following function and I am wanting to assign the variable "Quantity" to php variable using Ajax but, I am not don't know much about ajax so can someone please give me the code that will do the job. Thanks
var Quantity;
$("select").change(function() {
var str = "";
var price = <?php echo $row[price];?>;
$("select option:selected").each(function() {
str += $(this).text() + " ";
});
$(".plan_price").text("price : " + parseInt(str) * price + " baht");
Quantity = parseInt(str);
}).change();
function selectOne() {
var select = document.getElementById('quantity');
for (var i=0; i<<?php echo $row[item_amount]?>; i++) {
select.options[select.options.length] = new Option(i+1, i);
}
}
I want the quantity variable to be subtracted from the $row[item_amount] from the server
if ($row[item_amount] - Quantity == 0) {
$sql = "update item set active='2',item_amount=item_amount-Quantity,buy_time=NOW() where id='$id'";
} else {
$sql = "update item set item_amount=item_amount-Quantity,buy_time=NOW() where id='$id'";
}
$result = mysql_query($sql);