[SOLVED] Checkbox values need to be summed - Crosstec
Welcome, Guest
Please Login or Register.    Lost Password?

[SOLVED] Checkbox values need to be summed
(1 viewing) (1) Guest
Go to bottomPage: 1234
TOPIC: [SOLVED] Checkbox values need to be summed
#9829
Re: Checkbox values need to be summed 10 Months ago Karma: 16
Hi,

sorry thought there would be some other value from a textfield.

so try this in your summarize code then

Code:


value = ( !isNaN( bfField('cb1') ) ? bfField('cb1') : 0 ) + ( !isNaN( bfField('cb2') ) ? bfField('cb2') : 0 ) + ( !isNaN( bfField('cb3') ) ? bfField('cb3') : 0 ) + ( !isNaN( bfField('cb4') ) ? bfField('cb4') : 0 );

TheMuffinMan
Moderator
Posts: 769
graph
User Offline Click here to see the profile of this user
178152063 Gender: Male koelnkalk Location: Cologne - Germany Birthday: 03/07
The administrator has disabled public write access.
 
#9852
Re: Checkbox values need to be summed 10 Months ago Karma: 1
TheMuffinMan wrote:
Hi,

1. There is a way but it requires some work, if you can live with a summary page, then it will be the easiest.


I'm not afraid of doing a bit of programming. I looked at the Pizza Shop scripts but I just can't get the hang of the language that is used. Is there any documentation on the scripting language?
DavidLGCrawford
Fresh Boarder
Posts: 10
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#9853
Re: Checkbox values need to be summed 10 Months ago Karma: 1
I didn't see the previous reply, ignore my last message. Will try the previous suggestion.
DavidLGCrawford
Fresh Boarder
Posts: 10
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#9887
Re: Checkbox values need to be summed 10 Months ago Karma: 1
TheMuffinMan wrote:

Code:


value = ( !isNaN( bfField('cb1') ) ? bfField('cb1') : 0 ) + ( !isNaN( bfField('cb2') ) ? bfField('cb2') : 0 ) + ( !isNaN( bfField('cb3') ) ? bfField('cb3') : 0 ) + ( !isNaN( bfField('cb4') ) ? bfField('cb4') : 0 );



This doesn't work. It displayed the concatenated values, so I modified the code above by replacing "? bfField('cb1') :" with "? 10 :", the next with 20, and so on. When I tried the form I found that it added up ALL the values irregardless of whether the box was checked or not. So the test !isNaN isn't working.

Is there a simpler way, something like this:
Code:


if ( checked( bfField('cb1') ) )
{
  value = value + bfField('cb1');
}

DavidLGCrawford
Fresh Boarder
Posts: 10
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#9888
Re: Checkbox values need to be summed 10 Months ago Karma: 1
Okay, I solved the problem!

In each checkbox I created a CLICK action.
Code:

function ff_d11_action(element,action) {
ff_amountowing_action(element,action);
}



Then is the "amountowing" field I created this action:
Code:

function ff_amountowing_action(element,action)
{
   ff_getElementByName('amountowing').value = 0;
   if (ff_getElementByName('d11').checked)
   {
      ff_getElementByName('amountowing').value = Number(ff_getElementByName('amountowing').value) + Number(ff_getElementByName('d11').value);
   }
   if (ff_getElementByName('d12').checked)
   {
      ff_getElementByName('amountowing').value = Number(ff_getElementByName('amountowing').value) + Number(ff_getElementByName('d12').value);
   }
   if (ff_getElementByName('d13').checked)
   {
      ff_getElementByName('amountowing').value = Number(ff_getElementByName('amountowing').value) + Number(ff_getElementByName('d13').value);
   }
   if (ff_getElementByName('d14').checked)
   {
      ff_getElementByName('amountowing').value = Number(ff_getElementByName('amountowing').value) + Number(ff_getElementByName('d14').value);
   }
   if (ff_getElementByName('d16').checked)
   {
      ff_getElementByName('amountowing').value = Number(ff_getElementByName('amountowing').value) + Number(ff_getElementByName('d16').value);
   }
   if (ff_getElementByName('d18').checked)
   {
      ff_getElementByName('amountowing').value = Number(ff_getElementByName('amountowing').value) + Number(ff_getElementByName('d18').value);
   }
   if (ff_getElementByName('d1o').checked)
   {
      ff_getElementByName('amountowing').value = Number(ff_getElementByName('amountowing').value) + Number(ff_getElementByName('d1o').value);
   }
}



Took a while and alot of searching the source code of the form, but I started piecing the code together and got it working.

Would be nice if there was a code reference somewhere that tells all the commands, and what they do and their syntax.

Anyway, all working now, and all on one page too!
DavidLGCrawford
Fresh Boarder
Posts: 10
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
#10120
Re: Checkbox values need to be summed 9 Months, 1 Week ago Karma: 0
Thank you David for posting your solution!


It could be useful for some of us. It's nice!
izikit
Junior Boarder
Posts: 24
graphgraph
User Offline Click here to see the profile of this user
The administrator has disabled public write access.
 
Go to topPage: 1234
Moderators: , TheMuffinMan