<html>
<head>
<title>Demo Calculator by taking two inputs and adding</title>
</head>
<body>
<script language='JavaScript' type='text/JavaScript'>
<!--
var d1 = 0;
var d2 = 0;
function reset(){
output='';
data.length=0;
document.getElementById('t1').value=output;
document.getElementById('res').innerHTML=output;
document.getElementById('t1').focus()
}
function result(){
d1= parseFloat(document.getElementById('t1').value);
d2= parseFloat(document.getElementById('t2').value);
var res = d1 + d2 ;
document.getElementById('res').innerHTML=res;
}
//-->
</script>
<input type=text id=t1 style="TextAlign:Right;" size='6'> +
<input type=text id=t2 style="TextAlign:Right;" size='6'>
<input type=button value='=' size=5 onClick="result();">
<div id='res'></div>
</body>
</html>
mksharmil | 23-03-2014 |
nice job! if input boxes are arrays in multiple rows and id's are like ="txt[]" rather than "txt" how should we calculate then? |