srividya_kris
asked on
validate and evaluate arithmetic expressions
Can any one help me with a good code in javascript to validate and evaluate the arithmetic expression entered in a text box item.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sureshkumar:
It's nice to see a how someone cut and paste your code, change a little things and post it as a answer.
Question:
Where your code validate the expression?
xabi
It's nice to see a how someone cut and paste your code, change a little things and post it as a answer.
Question:
Where your code validate the expression?
xabi
<html>
<head>
<script>
<!--
function errorHandler(message,url,l
alert("Invalid expression")
return true
}
function doit(idform) {
eval ("idform.result.value = " + idform.expression.value)
}
window.onerror = errorHandler
//-->
</script>
</head>
<body>
<form name="myform">
Expression: <input type="text" name="expression"><br>
Result: <input type="text" name="result" readonly><br><br>
<input type="button" value="Evaluate" onclick="doit(this.form)">
</form>
</body>
</html>
xabi