annieoakley
06-09-2008, 10:17 PM
Hello,
I've got a form that loops through a dataset where a user will enter values in 2 columns and the third column is a formula containing the first 2 columns. The name of the field is going to change each time through the dataset (this is in .asp). I can't quite figure out how to get the calculated formula result back into the text field.
Here is an example of the code:
<% while not rs.eof %>
<TR class="GenTab">
<TD><%= rs("Name") %></td>
<TD><input type="text" name="GradeSpan<%= rs("code")%>" class="GenTab"></td>
<TD><input type="text" name="enroll<%= rs("code")%>" class="GenTab"></td>
<TD><input type="text" name="FTEStaff<%= rs("code")%>" value="0" class="GenTab" onBlur="CalcRatio();"></td>
<TD><input type="text" name="ratio<%= rs("code")%>" class="GenTab" readonly></td>
<TD></td>
</tr>
<% rs.movenext
wend
%>
So it loops through this with every result of the dataset. Here is the javascript function:
function CalcRatio(){
var theForm=document.main;
var x=theForm.sCode.value; (where this is rs(code) below)
var eInt, fInt, sTotal
eInt = eval('theForm.enroll' + x + '.value');
fInt = eval('theForm.FTEStaff' + x + '.value');
}
I then need this: eInt/fInt and assign it to the ratio textfield. What I can seem to do is something like this:
theForm.ratio+x+.value=eInt/fInt
I *can* do this:
var total = 'theForm.ratio' + x + '.value';
total = eInt/fInt
But still, can't then get that value back down into the textbox.
I hope this makes sense and *really* hope someone can help!!! TIA
I've got a form that loops through a dataset where a user will enter values in 2 columns and the third column is a formula containing the first 2 columns. The name of the field is going to change each time through the dataset (this is in .asp). I can't quite figure out how to get the calculated formula result back into the text field.
Here is an example of the code:
<% while not rs.eof %>
<TR class="GenTab">
<TD><%= rs("Name") %></td>
<TD><input type="text" name="GradeSpan<%= rs("code")%>" class="GenTab"></td>
<TD><input type="text" name="enroll<%= rs("code")%>" class="GenTab"></td>
<TD><input type="text" name="FTEStaff<%= rs("code")%>" value="0" class="GenTab" onBlur="CalcRatio();"></td>
<TD><input type="text" name="ratio<%= rs("code")%>" class="GenTab" readonly></td>
<TD></td>
</tr>
<% rs.movenext
wend
%>
So it loops through this with every result of the dataset. Here is the javascript function:
function CalcRatio(){
var theForm=document.main;
var x=theForm.sCode.value; (where this is rs(code) below)
var eInt, fInt, sTotal
eInt = eval('theForm.enroll' + x + '.value');
fInt = eval('theForm.FTEStaff' + x + '.value');
}
I then need this: eInt/fInt and assign it to the ratio textfield. What I can seem to do is something like this:
theForm.ratio+x+.value=eInt/fInt
I *can* do this:
var total = 'theForm.ratio' + x + '.value';
total = eInt/fInt
But still, can't then get that value back down into the textbox.
I hope this makes sense and *really* hope someone can help!!! TIA