Learn how to a build a cloud-first strategyRegister Now

x
Solved

# I need some help writing a script please?

Posted on 2008-11-12
Medium Priority
292 Views
I am hoping someone might be able to help me write a script.

I have 11 sections.

I need to calculate the TotalNoEntries and the TotalEntryFee.

You can see the field I require at http://www.tawfa.com.au/index.php?option=com_facileforms&Itemid=51

The code used to calculate thenumber of entries per section is:  (For example for Section4Entries:)

function ff_Section4Entries_action(element, action) { var oSectionTotal = ff_getElementByName('Section4TOTAL'); var oSectionEntries = ff_getElementByName('Section4Entries'); var cost = 44; switch (action) { case 'blur': oSectionTotal.value = oSectionEntries.value * cost; ff_CalculateTotalEntries(); ff_CalculateTotalAmount(); break; default:; } // switch } // ff_Section1Entries_action

Once you enter in a number for the number of entries, this script then calculates the total cost for that section.  In this example each entry is 44 dollars....so the total cost of the section is calculated from this code also.

I have 11 Sections  and I need to calculate the Total number of Entries and the Total Cost.

Section4Entries
0
Question by:Amanda Watson
• 12
• 7
• 3

LVL 10

Expert Comment

ID: 22947949
I am not an expert in this area, but i guess you could do

``````ff_CalculateTotalEntries()
{
var ent1 = ff_getElementByName('Section1Entries');
var ent1 = ff_getElementByName('Section2Entries');
..
var ent11 = ff_getElementByName('Section11Entries') ;
var total = 0 ;
if ( !isNan (ent1) ) total = total + ent1 ;
if ( !isNan (ent2) ) total = total + ent2 ;
..
if ( !isNan (ent11) ) total = total + ent11 ;

//Finally set tht total to the whoel total
ff_getElementByName('Section4TOTAL').setValue(total);
}
``````
0

LVL 10

Expert Comment

ID: 22947953
similarly you can compute the total values
0

LVL 11

Author Comment

ID: 22954516
Thanks for the code:

This was the final one I used:

ff_CalculateTotalNoEntries()
{
var ent1 = ff_getElementByName('Section1Entries');
var ent2 = ff_getElementByName('Section2Entries');
var ent3 = ff_getElementByName('Section3Entries');
var ent4 = ff_getElementByName('Section4Entries');
var ent5 = ff_getElementByName('Section5Entries');
var ent6 = ff_getElementByName('Section6Entries');
var ent7 = ff_getElementByName('Section7Entries');
var ent8 = ff_getElementByName('Section8Entries');
var ent9 = ff_getElementByName('Section9Entries');
var ent10 = ff_getElementByName('Section10Entries');
var ent11 = ff_getElementByName('Section11Entries') ;
var total = 0 ;
if ( !isNan (ent1) ) total = total + ent1 ;
if ( !isNan (ent2) ) total = total + ent2 ;
if ( !isNan (ent3) ) total = total + ent3 ;
if ( !isNan (ent4) ) total = total + ent4 ;
if ( !isNan (ent5) ) total = total + ent5 ;
if ( !isNan (ent6) ) total = total + ent6 ;
if ( !isNan (ent7) ) total = total + ent7 ;
if ( !isNan (ent8) ) total = total + ent8 ;
if ( !isNan (ent9) ) total = total + ent9 ;
if ( !isNan (ent10) ) total = total + ent10 ;
if ( !isNan (ent11) ) total = total + ent11 ;

//Finally set tht total to the whole total
ff_getElementByName('TotalNoEntries').setValue(total);
}

And I still recieved nothing in the field.

Any other ideas.

The section names are correct.....so I must be missing something.  I would be happy to show someone the backend programming as it might make more sense if you have a look through there....this has really stumped me!!
0

LVL 10

Expert Comment

ID: 22957505
btw, ate you calling this method in your code,

you were actually calling,  ff_CalculateTotalEntries(); in your code for section4
your new method name is ff_CalculateTotalNoEntries()

can you check this? also you need to call this method in all your section functions
0

LVL 11

Author Comment

ID: 22963771
I have changed it to be CalculateTotalEntries().

Still it didn't work.

What do you mean by needing to call this method in all my section functions?

I only used the above method in the script fot TotalNoEntries section.

Do I need to add this to each and every section from Section1Entries......through to Section11Entries?
0

LVL 11

Author Comment

ID: 23000705
Hello....can anyone help me finish this?
0

LVL 11

Author Comment

ID: 23053428
This is the only code used for each section - it comes in at Section11Entries, no code is use for Section11TOTAL and Section11Sizes  (applies to all sections Section1Entries, Section2Entries etc etc)

function ff_Section11Entries_action(element, action)
{
var oSectionTotal = ff_getElementByName('Section11TOTAL');
var oSectionEntries = ff_getElementByName('Section11Entries');
var cost = 44;

switch (action) {
case 'blur':
oSectionTotal.value = oSectionEntries.value * cost;
ff_CalculateTotalEntries();
ff_CalculateTotalAmount();
break;
default:;
} // switch
} // ff_Section1Entries_action

So this code will fill in the  Section11TOTAL as it does.  It is working correctly.

In the bottom section the functionss ff_CalculateTotalEntries(); and ffCalculateTotalAmount();  are where I think I need to add something:  The section names that are not working are TotalNoEntries and AllSectionsTOTAL .

switch (action) {
case 'blur':
oSectionTotal.value = oSectionEntries.value * cost;
ff_CalculateTotalEntries('TotalNoEntries');
ff_CalculateTotalAmount('AllSectionsTOTAL');
break;
default:;
} // switch
} // ff_Section1Entries_action

to each section... but that didn't work.

I tried adding this to each section:

switch (action) {
case 'blur':
oSectionTotal.value = oSectionEntries.value * cost;
ff_CalculateTotalNoEntries('');
ff_CalculateAllSectionsTOTAL('');
break;
default:;
} // switch
} // ff_Section1Entries_action

but that didn't work either...

So this is where my inexperience in programming is failing me....Can you help me along at all?
0

LVL 11

Author Comment

ID: 23053450
To link what I have just written, what I figured out is that new code doesn't need to be written as each section has the code I have shown which should be totaling what I want, but it isn't
0

LVL 75

Expert Comment

ID: 23054198
I wish I had the time to do this.

You can have one section total all

You can loop over form fields

But does the program (facileforms.js) you used to create this not have what you need?

0

LVL 11

Author Comment

ID: 23057609
Well I am not 100% sure.

If you have time to look at the component I have installed I could give you the username and password.

Its not that complicated, but I just don't know what I need to look for?

0

LVL 75

Expert Comment

ID: 23058664
Do they not have a help site and/or forum?
0

LVL 11

Author Comment

ID: 23062078
sure they do, but I havn't been able to get ANY response from then at all.  Not to mention it took over a week to register as they had to approve my registration.

Very frustrating.  I am in trouble as I didn't set this component up and I just have run out of resources for help.... I am truely hoping something will come from here
0

LVL 75

Expert Comment

ID: 23062419
where did you get

ff_getElementByName('TotalNoEntries').setValue(total);

I would think

ff_getElementByName('TotalNoEntries').value=total;

Let me know if that helps and if not I will dig deeper for you.
0

LVL 11

Author Comment

ID: 23073805
The TotalNoEntries is the correct name for the section required to get filled.

The top section of the code works that has
----------------------------------------------------------------------------------
function ff_Section11Entries_action(element, action)
{
var oSectionTotal = ff_getElementByName('Section11TOTAL');
var oSectionEntries = ff_getElementByName('Section11Entries');
var cost = 44;
------------------------------------------------------------------------------------
the bottom section is the problem and there is no  ff_getElementByName('TotalNoEntries').value=total;

it is only using  ff_CalculateTotalEntries();

Should I change that code?

-------------------------------------------------------------------------

switch (action) {
case 'blur':
oSectionTotal.value = oSectionEntries.value * cost;
ff_CalculateTotalEntries();
ff_CalculateTotalAmount();
break;
default:;
} // switch
} // ff_Section1Entries_action
----------------------------------------------------------------------------------
0

LVL 75

Expert Comment

ID: 23075052
Ok, I'll look when I have a spare moment
0

LVL 75

Accepted Solution

Michel Plungjan earned 2000 total points
ID: 23075267
Fixed it.You used to have section 1, section 2a section 3a,b,c and so onYou now have section 1-11If you replace
``````function ff_CalculateTotalEntries()
{var oTotalEntries=ff_getElementByName('TotalNoEntries');var cEntry
var cTotal=0;cEntry=ff_getElementByName('Section1Entries').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section2AEntries').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section2BEntries').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section3AEntries').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section3BEntries').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section3CEntries').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section3DEntries').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section3EEntries').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section3FEntries').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section3GEntries').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section3HEntries').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section4AEntries').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section4BEntries').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section4CEntries').value;if(cEntry!='')cTotal+=parseInt(cEntry);oTotalEntries.value=cTotal;}function ff_CalculateTotalAmount()
{var oTotal=ff_getElementByName('AllSectionsTOTAL');var oGrandTotal=ff_getElementByName('GRANDTOTAL');var cEntry
var cTotal=0;cEntry=ff_getElementByName('Section1TOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section2ATOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section2BTOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section3ATOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section3BTOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section3CTOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section3DTOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section3ETOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section3FTOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section3GTOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section3HTOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section4ATOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section4BTOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);cEntry=ff_getElementByName('Section4CTOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);oTotal.value=cTotal;cEntry=ff_getElementByName('CourierCharge').value;if(cEntry!='')cTotal+=parseInt(cEntry);
oGrandTotal.value=cTotal;}

with

function ff_CalculateTotalEntries() {
var oTotalEntries=ff_getElementByName('TotalNoEntries');
var cEntry;
var cTotal=0;
cEntry=ff_getElementByName('Section1Entries').value; if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section2Entries').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section3Entries').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section4Entries').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section5Entries').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section6Entries').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section7Entries').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section8Entries').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section9Entries').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section10Entries').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section11Entries').value;if(cEntry!='')cTotal+=parseInt(cEntry);
oTotalEntries.value=cTotal;
}

function ff_CalculateTotalAmount() {
var oTotal=ff_getElementByName('AllSectionsTOTAL');
var oGrandTotal=ff_getElementByName('GRANDTOTAL');
var cEntry;
var cTotal=0;
cEntry=ff_getElementByName('Section1TOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section2TOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section3TOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section4TOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section5TOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section6TOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section7TOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section8TOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section9TOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section10TOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);
cEntry=ff_getElementByName('Section11TOTAL').value;if(cEntry!='')cTotal+=parseInt(cEntry);
oTotal.value=cTotal;
cEntry=ff_getElementByName('CourierCharge').value;if(cEntry!='')cTotal+=parseInt(cEntry);
oGrandTotal.value=cTotal;
}

then it all works
``````
0

LVL 11

Author Comment

ID: 23080335
Thats great.  Where did you find this script?
I have been looking for where to change this script and cannot find it anywhere?
0

LVL 11

Author Comment

ID: 23080399
My understanding is that the script in each section will calculate the total progressively.

What you have provided tells me that there is a script required for the TotalNoEntries section for example.  When this question started, I tried writing a new script but that isn't what needed to be done.  (I could be wrong of course).

You are right, I did change the section names from Section1A etc to Section1, Section2, Section3 etc etc, but I changed each sections code to reflect that.  You have pulled some code from somewhere, is that right?

Where did you get this code?  Am I to assume that the original scripts are now not working and I need to add this script you have provided, or am I to replace it somewhere.  If so, where?
0

LVL 75

Expert Comment

ID: 23084093
The script starts halfway in on line 187 of the url you gave

You need to leave
break;default:;}}
in and remove from

line 187: break;default:;}}function ff_CalculateTotalEntries()
.
.
.
to and including
line200: oGrandTotal.value=cTotal;}
0

LVL 75

Expert Comment

ID: 23084138
I also see some oddly named sections here (maybe no problem)

var ff_elements=[...,
['ff_elem160','ff_div160','SECTION',1,160],
['ff_elem161','ff_div161','NoOfEntries',1,161],['ff_elem162','ff_div162','Size',1,162],['ff_elem163','ff_div163','SectionEntryFee',1,163],
['ff_elem164','ff_div164','SECTION1',1,164],['ff_elem165','ff_div165','Section1Entries',1,165],['ff_elem166','ff_div166','Section1Sizes',1,166],['ff_elem167','ff_div167','Section1TOTAL',1,167],
['ff_elem169','ff_div169','SECTION2',1,169],['ff_elem170','ff_div170','Section2Entries',1,170],['ff_elem171','ff_div171','Section2Sizes',1,171],['ff_elem172','ff_div172','Section2TOTAL',1,172],
['ff_elem173','ff_div173','SECTION2b',1,173],
['ff_elem174','ff_div174','Section3Entries',1,174],
['ff_elem175','ff_div175','Section3Sizes',1,175],
['ff_elem176','ff_div176','Section3TOTAL',1,176],
['ff_elem178','ff_div178','SECTION3A',1,178],
['ff_elem179','ff_div179','Section4Entries',1,179],
['ff_elem180','ff_div180','Section4Sizes',1,180],
['ff_elem181','ff_div181','Section4TOTAL',1,181],
['ff_elem182','ff_div182','SECTION3B',1,182],
['ff_elem183','ff_div183','Section5Entries',1,183],
['ff_elem184','ff_div184','Section5Sizes',1,184],
['ff_elem185','ff_div185','Section5TOTAL',1,185],
['ff_elem186','ff_div186','SECTION3C',1,186],
['ff_elem187','ff_div187','Section6Entries',1,187],['ff_elem188','ff_div188','Section6Sizes',1,188],['ff_elem189','ff_div189','Section6TOTAL',1,189],
['ff_elem190','ff_div190','SECTION3D',1,190],
['ff_elem191','ff_div191','Section7Entries',1,191],['ff_elem192','ff_div192','Section7Sizes',1,192],['ff_elem193','ff_div193','Section7TOTAL',1,193],
['ff_elem194','ff_div194','SECTION3E',1,194],
['ff_elem195','ff_div195','Section8Entries',1,195],['ff_elem196','ff_div196','Section8Sizes',1,196],['ff_elem197','ff_div197','Section8TOTAL',1,197],
['ff_elem198','ff_div198','SECTION3F',1,198],
['ff_elem199','ff_div199','Section9Entries',1,199],['ff_elem200','ff_div200','Section9Sizes',1,200],['ff_elem201','ff_div201','Section9TOTAL',1,201],
['ff_elem202','ff_div202','SECTION3G',1,202],
['ff_elem203','ff_div203','Section10Entries',1,203],['ff_elem204','ff_div204','Section10Sizes',1,204],['ff_elem205','ff_div205','Section10TOTAL',1,205],
['ff_elem242','ff_div242','SECTION3H',1,242],
['ff_elem243','ff_div243','Section11Entries',1,243],['ff_elem244','ff_div244','Section11Sizes',1,244],['ff_elem245','ff_div245','Section11TOTAL',1,245],
['ff_elem218','ff_div218','TOTAL_ENTRIES',1,218],['ff_elem219','ff_div219','TotalNoEntries',1,219],['ff_elem220','ff_div220','TotalEntryFee',1,220],['ff_elem222','ff_div222','AllSectionsTOTAL',1,222],
...
];

0

LVL 11

Author Closing Comment

ID: 31516137
0

LVL 11

Author Comment

ID: 23100401
This needed to be added to EACH section!!

function ff_Section3Entries_action(element, action)
{
var oSectionTotal = ff_getElementByName('Section3TOTAL');
var oSectionEntries = ff_getElementByName('Section3Entries');
var cost = 44;

switch (action) {
case 'blur':
oSectionTotal.value = oSectionEntries.value * cost;
ff_CalculateTotalEntries();
ff_CalculateTotalAmount();
break;
default:;
} // switch
}

function ff_CalculateTotalEntries()
{
var oTotalEntries = ff_getElementByName('TotalNoEntries');
var cEntry
var cTotal = 0;

cEntry = ff_getElementByName('Section1Entries').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section2Entries').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section3Entries').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section4Entries').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section5Entries').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section6Entries').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section7Entries').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section8Entries').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section9Entries').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section10Entries').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section11Entries').value;
if (cEntry != '') cTotal += parseInt(cEntry);

oTotalEntries.value = cTotal;
}

function ff_CalculateTotalAmount()
{
var oTotal = ff_getElementByName('AllSectionsTOTAL');
var cEntry
var cTotal = 0;

cEntry = ff_getElementByName('Section1TOTAL').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section2TOTAL').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section3TOTAL').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section4TOTAL').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section5TOTAL').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section6TOTAL').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section7TOTAL').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section8TOTAL').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section9TOTAL').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section10TOTAL').value;
if (cEntry != '') cTotal += parseInt(cEntry);
cEntry = ff_getElementByName('Section11TOTAL').value;
if (cEntry != '') cTotal += parseInt(cEntry);

oTotal.value = cTotal;
}
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the bâ€¦
The viewer will learn how to count occurrences of each item in an array.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and â€¦
###### Suggested Courses
Course of the Month20 days, 14 hours left to enroll