What I want to do is the numbers entered by the user and the sum of the numbers returned. My logic is this:
- User enters a string
- The string is split into an array
- Scroll the array and sum all the numbers
- Refundable amount
And here is the code that I still have:
<script type='text/javascript'> var val=document.getElementById('userInput').value; var temp=val.split(" "); function sum() { for(var i=0, MISSING THIS BIT document.getElementById('resultSum').innerHTML=MISSING THIS BIT; } </script> <form name="input"> <textarea name="userInput" rows=20 cols=20></textarea> <input name="Run" type=Button value="run" onClick="sum()"> <form name="resultSum"><input type=Text>
I admit with sympathy that this is most likely wrong, and appreciate any time and effort.
UPDATE: I did this as a suggestion, and I got the following error in my code below:
Message: 'document.getElementById (...)' is a null or not object. String: 16 Char: 1 Code: 0
<html> <script type='text/javascript'> function sum(){ var val = document.getElementById('userInput').value; var temp = val.split(" "); var total = 0; var v; for(var i = 0; i < temp.length; i++) { v = parseFloat(temp[i]); if (!isNaN(v)) total += v; } document.getElementById('resultSum').innerHTML=total; } </script> <form name="input"> <textarea name="userInput" rows=20 cols=20></textarea> <input name="Run" type=Button value="run" onClick="sum()"> <form name="resultSum"><input type=text> <html>
Any suggestions? Thanks to everyone for being comprehensive - I read both examples and understood the process now!
source share