How can I get an alert input variables amount and percent in scriptable JS and assign both variables to an HTML variable to make a Tax calculation and display it in a WebView.loadHTML…?
Or please, recommend me another way to do this. This is my first JS.
The code:
var amountInput = new Alert();
amountInput.title = "IVU";
amountInput.message = "Type ticket amount and IVU";
amountInput.addTextField("Amount");
amountInput.addTextField("IVU");
amountInput.addAction("OK");
await amountInput.present();
console.log("Hello " + amountInput.textFieldValue(0) + " " + amountInput.textFieldValue(1));
var html = `
<!DOCTYPE html>
<html>
<head>
<h2>IVU</h2>
<p>Impuesto de ventas y uso</p>
<style>
input{
padding: 10px;
font: 20px Arial;
width: 15%;
}
</style>
</head>
<body style="background-color:DarkSeaGreen; color:MidnightBlue; font-family:avenir; font-size:400%; text-align: center;">
<p id="output"></p>
<script type="text/javascript">
let percent = 11.5 // want a var here instead of 11.5 percent
let amount = 100 // want a var here instead of 100 amount
var ivu = (percent / 100)
var totalIvu = (ivu * amount).toFixed(2)
var totalAmount = Math.round(amount * (ivu + 1) * 100).toFixed(2) / 100
document.getElementById("output").innerHTML = "IVU " + percent + "%" + "<br><br>" + "Bill " + amount + "<br><br>" + "Ivu " + "$" + totalIvu + "<br><br>" + "Total " + "$" + totalAmount;
</script>
</body>
`;
WebView.loadHTML(html, null, new Size(0, 100));
Script.complete();