calculate all elements in array call with button
trying to sum all elements in the array "number" have in shown in the form "output" when user clicks on the button, im using a example i found on the net but cant seem to make it owrk or any other example if any can pls help me to understand thanks
[COLOR="#EE82EE"]<body>
<script type="text/javascript">
var number = [];
Array.prototype.sum = function()
{
for (var i = 0, L = this.length, sum = 0; i < L; sum += this[i++]);
return sum(document.getElementById("output").value);
}
function myFunction() {
var x = document.getElementById("box");
number.push(document.getElementById("input").value);
x.innerHTML = number.join('<br/>');
}
function myReset() {
number=[]
number.splice(0);
var x = document.getElementById("box");
x.innerHTML = "";
x.innerHTML = number.join('<br/>');
}
</script>
<form>
<input id="input" type=text>
<input type=button onclick="myFunction()" value="Add to list"/>
</form>
<div id="box" style="border:1px solid black;width:150px;height:150px;overflow:scroll">
</div>
<form>
<input type=button onclick="number.sum()" value="Calculate"/>
<input type=button onclick="myReset()" value="Reset" /> </br></br>
<b>Total(sum):</b></br>
<input id="output" type=text>
</form>
</body>