Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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

Reply With Quote
  #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

Reply With Quote
  #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

Reply With Quote
  #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

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:28 AM.


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