Javascript Calculator Using Eval

Javascript Calculator Using Eval

Eval is a function both resides in either Javascript or PHP. Eval is used for execute an argument. In this case, I ll try to share simple Javascript Calculator Using Eval. However, unlike other calculator that have buttons “1-9” and “*/+-“, we dont have to put those buttons. Because this is a computer programs, so the user can input it from their keyboard.

This code is divided into 2 types. The Javascript code and the HTML form code.

Lets start with the HTML code first.

<input type="text" id="query" />
<input type="button" value="calculate" onclick="calc()" />
<input type="text" id="result" disabled />

Last but not least, the Javascript as the engine of this program.

function calc(){
	str = document.getElementById('query').value;
	document.getElementById('result').value = eval(str);

In thid case, the eval will execute the string that inputed by you in the frist text box.

Our Javascript Calculator Using Eval here can calculate a simple calculation such as addition, reduction, multiplication and division. It also can handle parenthesis.

I wish this Javascript Calculator Using Eval is useful for you.

Good Luck

Related Post:

PHP Calculator Using Eval


One response to “Javascript Calculator Using Eval

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: