Quote (T_O_K_I_O @ Apr 23 2015 07:19am)
I don't post here too much , but I am having a hard time figuring out this last bit of JavaScript
<html>
<script language="JavaScript">
function Calculate(value)
{
document.getElementById("ResponseDisplayArea").innerHTML="<h1>The answer is "+value
}
</script>
<form>
Enter a mathematical expression (e.g.- 2+2-3) and click the Evaluate button
<p><input type="text" name="expression"></p>
<input type="button" value="Evaluate" onClick=Calculate(expression.value)>
<input type="reset">
</form>
<div id="ResponseDisplayArea"></div>
</html>
I am trying to display the answer "The answer is ***" in the second division. Just cannot figure out how .
My results thus far have displayed "The answer is 2+2" the expression entered.
You want the eval() function:
http://www.w3schools.com/jsref/jsref_eval.aspeval("2 + 2") = 4
The answer is eval(value)