Nuffnang Ads

Thursday, 4 September 2014

Simple calculator using Javascript - part 1

This time another tutorial to make a simple calculator that will receive two input and will add both inputs.Basically it will look like this:-

1) Open an editor (notepad, notepad++, etc)
2) Put the following codes at the editor:-

<html>
<body>
<h3> Simple Calculator </h3>
<script language="JavaScript">

function addNum()
{
num1=parseInt(document.frmadd.txt1.value);
num2=parseInt(document.frmadd.txt2.value);
num3=num1+num2;
document.frmadd.txt3.value=num3;
}
</script></head><body>
<form name="frmadd">

Num1<input type ="text" name="txt1" ><br>
Num2<input type ="text" name="txt2" ><br>
Result<input type ="text" name="txt3" disabled><br>

<input type="button" value="Add" name"but1" onClick="addNum()">

</form>
</body></html>

3) Save and Run.


4) You can challenge yourself by creating another mathematical operation like subtraction, multiplication, division

No comments:

Post a Comment