How do you parse a split() textarea?
I'm trying to create an aggregates calculator where the sum & average are calculated from the user inputs textarea of values, which i have split(). This is my code so far. I'm sure I'm not using the variables or parseFloat method correctly.
document.getElementById("answer").value+=(document.getElementById("num1").value) + '\n';
var total = "sa";
var sa = textAreaText.split("\n");
for (var i=0; i < sa.length; i++)
parseFloat(sa[i]) + total;
document.getElementById("sum").value = total;
document.getElementById("average").value = total / sa.length;
<h3>Add as many numbers as you like<br>to the list,then click Calculate.</h3>
<form name="entryForm" id="entryForm">
<input type="text" id="num1"></input>
<input type="button" value="Add to list" onclick="add();"><br>
<textarea name="text" rows="15" cols="20" readonly="readonly" id="answer"></textarea><br>
<input type="button" value="Calculate" onclick="calculate">
<input type="reset" value="Reset">
<input type="text" id="sum" value="0"><br>
<input type="text" id="average" value="0">
1) You have syntax and logic errors, but overall you are reasonably close.
2) In the future, posted code is much easier to read if you wrap the code in code tags by first highlighting your code and then click the # icon in the editor's toolbar.
webdev1958 THANK YOU!
I've spent about 40 hours trying to figure this out and will now spend another 40 studying your code until I completely understand it.
Do you by chance have perl CGI version to do the same thing? I was struggling with this in perl CGI. Thank you in advance!
Post in the PERL forum.
It will have to process SUBMITTED data, no data that is live in the browser.
|All times are GMT +1. The time now is 05:01 PM.|
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.