Wednesday, 28 August 2013

js wont show result of calculation

js wont show result of calculation

Quick newbie question, i'm sure it is simple to you, but i cant get my
head around to figure out why my code wont work. Checked online, seems
that i'm doing everything fine, but still wont work... All i'm trying to
do, is to make simple calc and display that in diff field. I have tryed
external and internal JS. Here's my code:
<script type="text/javascript">
function calculate(){
var a = document.calculate.first.value;
var b = document.calculate.second.value;
var c = parseInt(a) + parseInt(b);
document.calculate.result.value = c;
}
</script>
<body>
<form name="calculate">
<input type="text" name="first" size="5">
<input type="text" name="second" size="5">
<input type="button" onclick="calculate()">
<input type="text" name="result" id="result" size="5">
</form>
</body>

No comments:

Post a Comment