0
I have a file called somar.js which contains some Jquery commands, among them the sum of the packages * daily exchange value, but these values come from the database. To prevent the administrator from manually registering on the system and this 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 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);
}
Inside a *.js file, it is not possible to put php commands. If the script is in html and not in a . js file, it is possible. In your case it would be interesting to create a global javascript variable and load the value of the database into it.
– Jhonatan Simões
Hi Jhonatan, but how would I load the value of the bank? I am a little layman in Jquery.
– user24136
Good inside the js file without chance. You already have the connection of the database and the variable php with the value? If yes put the solution I thought for you
– Jhonatan Simões
Hi Jhonatan, I do. The system was developed in PHP/Mysql.
– user24136