I have a file called somar.js where it contains some JQuery commands, including the sum of the packets * daily exchange value, but these values come from the database. To prevent the administrator from registering on the system and manually in that file, I would like to know if it is possible to bring mysql results inside JQuery or insert PHP commands into js files. See below the section that I need this solution:
var taxaCambio = 4.20; // Nessa linha
var totalGeralSomar = total1 + total2 + total3 + total4;
var totalCambio = totalGeralSomar * taxaCambio;
if(totalGeralSomar.toFixed(2) == "NaN" || totalCambio.toFixed(2) == "NaN"){
document.getElementById("totalGeral").innerHTML = "R$ 0.00";
document.getElementById("subTotal").innerHTML = "USD 0.00";
}else{
Number.prototype.formatMoney = function(c, d, t){
var n = this,
c = isNaN(c = Math.abs(c)) ? 2 : c,
d = d == undefined ? "." : d,
t = t == undefined ? "," : t,
s = n < 0 ? "-" : "",
i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
j = (j = i.length) > 3 ? j % 3 : 0;
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
};
document.getElementById("totalGeral").innerHTML = "R$ " +(totalCambio).formatMoney(2, ',', '.');;
document.getElementById("subTotal").innerHTML = "USD " +totalGeralSomar.toFixed(2);
}