Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
  #11 (permalink)  
Old March 3rd, 2006, 06:11 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

  #12 (permalink)  
Old March 3rd, 2006, 06:56 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

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

  #13 (permalink)  
Old March 3rd, 2006, 08:52 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

  #14 (permalink)  
Old March 6th, 2006, 05:27 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Chris you're a life saver that script worked perfectly.
I've now finished my website form.

Jayman





Similar Threads
Thread Thread Starter Forum Replies Last Post
populating online text fields etc hamilton C# 2 June 20th, 2007 09:16 AM
Select fields & calculating age miki-pt Access ASP 1 November 26th, 2006 06:16 PM
Combining Text Fields lizhaskin Access VBA 1 May 1st, 2006 06:15 AM
specifying number of text fields Astro VB How-To 64 August 9th, 2005 08:02 PM
MySQL Text Fields MAtkins General .NET 0 May 27th, 2005 03:17 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.