I need help this is really hard to explain I am making a calculator type program. And the main bit where it calculates it wont. it needs to calculate from multiple textboxs and combine them into one readable string. That needs to be run as math. but i can not run it as math, I can only manage to run it as a text. not as equation. is there any way i can change it so it treats it like math. I am a student I am still learning js.
I have tried changing the var name and changing the text function but have not been able to fix it here is the code so you can help:
function add() {
var value = parseInt(document.getElementById('number').value, 10);
value = isNaN(value) ? 0 : value;
value++;
window.value=value;
document.getElementById('number').value = window.value;
var num = "v"+window.value;
var node = document.createElement("a");
var x = document.createElement("INPUT");
x.setAttribute("type", "text");
x.setAttribute("id", num);
node.appendChild(x);
document.getElementById("myList").appendChild(node);
}
function equal() {
var str = "";
var ans = "";
for (var i = 1; i <= window.value; i++) {
str = "v"+i;
this is what i need to be treated as math:
ans += document.getElementById(str).value;
rest of javascript:
}
document.getElementById("demo3").innerHTML = ans;
}
if it is any help here is the html:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body onload="numnum();"></body>
<input id="number" type="hidden"></input>
<p id="demo"></p>
<p id="demo2"></p>
<p>Click the button to create a Text Field.</p>
<a id="myList"></a>
<button onclick="add()">+</button>
<button onclick="equal()">=</button>
<p id="demo3"></p>
<script src="input.js"></script>
</body>
</html>
thankyou