1

I have created a Drupal website with a new page for registration purposes. I would like to have a checkbox list of my provided services (for example back-up user files), with the corresponding prices next to each service.

When multiple checkboxes are checked, the values (in this case, the prices) need to sum up to a total amount. This amount then should be displayed on the page.

How can I sum the amounts associated with the checkboxes?

KatieK
  • 13,586
  • 17
  • 76
  • 90
DinoD
  • 35
  • 2

2 Answers2

1

Look into the Computed Field module.

Computed Field is a very powerful CCK field module that lets you add a custom "computed fields" to your content types. These computed fields are populated with values that you define via PHP code. You may draw on anything available to Drupal, including other fields, the current user, database tables, you name it. (Feeling the power yet? :) ) You can also choose whether to store your computed field values in the database with other content fields, or have them "calculated" on the fly during node views. (Although you should note that Views use requires database stored values.) This field is literally the Swiss Army knife of CCK fields. So start cooking up your PHP based values!

nmc
  • 8,724
  • 5
  • 36
  • 68
1

You have the checkbox value attribute to attach the price amount to a checkbox? While submitting/processing use js/php logic to add the selected checkboxes.

Update: options array should be like this

array('return_value1' => t('Display Value 1'), 'return_value2' => t('Display Value 2'))
Quicksilver
  • 2,546
  • 3
  • 23
  • 37
  • Not exactly, i have found a way to make a array of checkboxes. And loop through the array to find whether a checkbox is check or not. But i still can't add the price as a value to the checkbox. – DinoD Jul 03 '12 at 09:25
  • That works ! THANK YOU VERY MUCH !!! I have used this code [link](http://stackoverflow.com/questions/1965075/jquery-loop-through-checkboxes-and-count-each-one-checked-or-unchecked) – DinoD Jul 03 '12 at 11:31