Feedback on: irt.org FAQ Knowledge Base Q48
Length:
Too short
Comments:
This is just a small piece of the code. How do you parse it in the HTML? If I had ten text fields with numbers entered in each, and the user hit a "submit" button, how do I pass the total to a text box?
Paul
Worth:
Very worth reading
Comments:
Thanks, quickly found the answer for which I was looking.
Great Job!
Worth:
Very worth reading
Length:
Just right
Comments:
But... it still doesn't say how to actually sum form fields...
Where Q1 through Q3 are radio buttons each with values 1 through 4, this code produces NaN.
function validate_form() {
a = document.form.Q1.value;
b = document.form.Q2.value;
c = document.form.Q3.value;
total = a + b + c;
alert ("Total = " + total);
return validity;
}
Length:
Too short
Comments:
this is an example of how to
do what the question asks.
first the form variables are convertd to numbers ie
var QDT = DAILYFORM.QTYDAILYTICKETS.value - 0;
then the calc is done and the result is loaded back into a form
text field by using + ''.
function calcdepqty()
{
var result = 0;
var QDT = 0;
var QN = 0;
var VBQ = 0;
var V = 0;
var WEQ = 0;
var QDT = DAILYFORM.QTYDAILYTICKETS.value - 0;
var WEQ = DAILYFORM.WEQTY.value - 0;
var QN = DAILYFORM.QTYNIGHT.value - 0;
var VBQ = DAILYFORM.VALIDBILLQTY.value - 0;
var V = DAILYFORM.VOID.value - 0;
result = QDT + WEQ + QN + VBQ + V;
DAILYFORM.DEPOSITQTY.value = result + '';
}
</SCRIPT>