Gossamer Forum
Home : Products : DBMan : Customization :

Calculating totals with select fields

Quote Reply
Calculating totals with select fields
I am looking for a way to calculate totals with select fields I can easily do it with each field using ($in{$db_key} to collect field info and add values per field name but I am not sure how to add a value to each select field. Any ideas would be appreciated.

Thanks, Mark

http://www.mediamasters.net
Innovative web design and e-business solutions...
1-253-853-1731
Quote Reply
Re: Calculating totals with select fields In reply to
Can I get an example of what you're trying to do?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Calculating totals with select fields In reply to
You must live here, lol!

Thanks for the quick reply,

At the end of the form there's a couple of radio options with dollar amounts attached I need to in the success sub display the total of those selections

Say the field name is:
Crayons
radio 1 is red at $10.00
radio 2 is blue at $20.00, etc.

Does this make sense?

Thanks, Mark



http://www.mediamasters.net
Innovative web design and e-business solutions...
1-253-853-1731
Quote Reply
Re: Calculating totals with select fields In reply to
How are the radio buttons defined? What is the name for the buttons and what values are passed?

JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: Calculating totals with select fields In reply to
They are currently just text values. I had to stop and work on some other projects sometimes that helps me come up with the answer but not so far this evening.

it is defined in the .cfg as a standard option like this

%db_radio_fields = (
'Tournament Type' => 'Monthly Tournament $50.00 ea. Person,Shotgun Tournament $35.00 ea. Person,Monday Shotgun Tournament $37.00 ea. Person'
'Dining Package' => 'Package A $25.00 ea. person,Package B $30.00 ea. person,Package C $22.00 ea. person'
);

I need to pass the individual option value of each field when they are selected and then add the total of two or three of these fields. Oh ya! then I need to add a field to enter the number of players that will in turn multiply that total amount.

:o)-Mark

http://www.mediamasters.net
Innovative web design and e-business solutions...
1-253-853-1731
Quote Reply
Re: Calculating totals with select fields In reply to
This is what I needed. Smile

The thing we first need to do is pull the price out of the text. Hmmmm.

Code:

$price_tournament = $rec{'Tournament Type'};
$price_tournament =~ s/.+\$//;
$price_tournament =~ s/\.00.+//;

$price_dining = $rec{'Dining Package'}'
$price_dining =~ s/.+\$//;
$price_dining =~ s/\.00.+//;

$price_per_person = $price_tournament + $price_dining;
$total_price = $price_per_person * $rec{'Number of People'};
This would go into sub html_record, I think. Smile Since all of your prices are even dollars, it's a lot easier. To format the totals, just use

$price_per_person = '$' . $price_per_person . '.00';
$total_price = '$' . $total_price . '.00';


JPD
http://www.jpdeni.com/dbman/
Quote Reply
Re: [JPDeni] Calculating totals with select fields In reply to
Does it make a difference if you are using the short/long display with the default.html? And where exactly would you place the code you provided? You have to excuse me...this is the first time I have every created a formula in Perl Blush

$price_tournament = $rec{'Tournament Type'};
$price_tournament =~ s/.+\$//;
$price_tournament =~ s/\.00.+//;

$price_dining = $rec{'Dining Package'}'
$price_dining =~ s/.+\$//;
$price_dining =~ s/\.00.+//;

$price_per_person = $price_tournament + $price_dining;
$total_price = $price_per_person * $rec{'Number of People'};
[/pre]$price_per_person = '$' . $price_per_person . '.00';
$total_price = '$' . $total_price . '.00';

Cher