I am trying to transfer a javascript variable to a math.js function. The variable (denexp) is obtained by getElementById as follows:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="https://unpkg.com/mathjs@6.2.2/dist/math.min.js"></script>
<style>
body {
font-family: sans-serif;
}
</style>
</head>
<body>
<canvas id=canvas1 width=1600 height=400></canvas>
<canvas id=canvas2 width=800 height=400></canvas>
<table>
<tr>
<th>den</th>
<th><input type="number" id="denid" value="1.0" min="0"> </th>
</tr>
</table>
<script>
const sim = math.parser()
const denexp = document.getElementById("denid").value;
sim.evaluate("G = denexp") // Density
</script>
</body>
</html>
It seems, however, that math.js
cannot read denexp
I get the following error:
Uncaught Error: Undefined symbol denexp
Do you have any ideas?