 |
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0 |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

March 3rd, 2006, 06:11 AM
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
I only changed a few of the textfield boxes to the name of "textfield[n]" to test the formula.
However,the other textfield boxes have all got different names ranging from something "StartWord","Typing","Select" etc.
The total_score[n] boxes have a different number of text boxes to add up.
Jayman
Quote:
quote:Originally posted by ChrisScott
Hi Jayman,
Ok, I think I get what you mean.
What are the names of the text boxes that you are going to add up for Total_Score2, Total_Score3 etc - do they continue as Textfield3, Textfield4 and so on?
Does each Total_Score[n] have the same number of text boxes to add up?
Cheers,
Chris
|
|

March 3rd, 2006, 06:56 AM
|
Friend of Wrox
|
|
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
|
|
Hi Jayman,
You could do something like...
Code:
function CalcTotal(pForm, pTotalField, pFieldsToAdd){
var fldArr = pFieldsToAdd.split(",");
var total = 0;
for(var i = 0; i < fldArr.length; i++){
var fld = pForm[fldArr[i]];
if(!isNaN(fld.value) && fld.value != ""){
total += parseFloat(fld.value);
}
}
pForm[pTotalField].value = total;
}
...
<form id="myForm" name="myForm" action="">
<input id="myField1" name="myField1" type="text" onkeyup="CalcTotal(this.form, 'myTotalField', 'myField1,myField2,myField3');" />
<input id="myField2" type="text" onkeyup="CalcTotal(this.form, 'myTotalField', 'myField1,myField2,myField3');" />
<input id="myField3" type="text" onkeyup="CalcTotal(this.form, 'myTotalField', 'myField1,myField2,myField3');" />
<input id="myTotalField" type="text" />
</form>
Then just repeat with different parameters for your other fields.
HTH,
Chris
|

March 3rd, 2006, 08:52 AM
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks i'll let you know how i get on
Jayman
Quote:
quote:Originally posted by ChrisScott
Hi Jayman,
You could do something like...
Code:
function CalcTotal(pForm, pTotalField, pFieldsToAdd){
var fldArr = pFieldsToAdd.split(",");
var total = 0;
for(var i = 0; i < fldArr.length; i++){
var fld = pForm[fldArr[i]];
if(!isNaN(fld.value) && fld.value != ""){
total += parseFloat(fld.value);
}
}
pForm[pTotalField].value = total;
}
...
<form id="myForm" name="myForm" action="">
<input id="myField1" name="myField1" type="text" onkeyup="CalcTotal(this.form, 'myTotalField', 'myField1,myField2,myField3');" />
<input id="myField2" type="text" onkeyup="CalcTotal(this.form, 'myTotalField', 'myField1,myField2,myField3');" />
<input id="myField3" type="text" onkeyup="CalcTotal(this.form, 'myTotalField', 'myField1,myField2,myField3');" />
<input id="myTotalField" type="text" />
</form>
Then just repeat with different parameters for your other fields.
HTH,
Chris
|
|

March 6th, 2006, 05:27 AM
|
Authorized User
|
|
Join Date: Jan 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Chris you're a life saver that script worked perfectly.
I've now finished my website form.
Jayman
|
|
 |