View Single Post
Old 03-08-2012, 02:42 AM   PM User | #1
CAO
New to the CF scene

 
Join Date: Mar 2012
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
CAO is an unknown quantity at this point
How do you parse a split() textarea?

Hey
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.
Any advise?
Many Thanks


<html>
<head>
<script type="text/javascript">
<!--

function add()
{
document.getElementById("answer").value+=(document.getElementById("num1").value) + '\n';
}


function calculate()
{
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;
}
}



//-->
</script>
</head>
<body>
<h1>Aggregates</h1>

<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">

<p>Total (Sum);</p>

<input type="text" id="sum" value="0"><br>

<p>Average :</p>

<input type="text" id="average" value="0">

</form>

</body>
</html>
CAO is offline   Reply With Quote