I want to assign a value ($productVatValue) taking from php to javascript using JSON, how I can achieve that for my code?
here is the code on Javascript
var vat = (Number($("#subTotal").val())/100) * $productVatValue;
vat = vat.toFixed(2);
$("#vat").val(vat);
$("#vatValue").val(vat);
and here is the fetchOrderVat.php that calls the vat value
<?php
require_once 'core.php';
$sql = "SELECT vat FROM usercompany WHERE id = 1";
$result = $connect->query($sql);
if($result->num_rows > 0) {
$row = $result->fetch_array();
} // if num_rows
$connect->close();
echo json_encode($row);
There is a little change in your first line of javascript code.
Simply change
var vat = (Number($("#subTotal").val())/100) * $productVatValue;
to
var vat = (Number($("#subTotal").val())/100) * <?php echo $productVatValue; ?>
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.