Ive made a booking form using Drupal 6, where bookings are a content type and you create a node of that type to make a booking.

I now need to add a price calculator. When creating a booking node, one of the CCK fields you fill in is distance. I then need the price to be calculated from the rates below, and that value to be given to another CCK field.

Rates: 0-5 km $20/ mile 5-10 km $15/ mile 10-20 km $10/ mile 20-30 km $5/ mile

So if the distance was 11km, the price would be 11 x 15 = 165. Also, the rates table needs to be editable by the site admin.

Can any modules do or at least help with this? I could probably manage to do the calculations and change the price field value with jQuery. If the table was shown on the page then jQuery could grab the values from it, and the table could be editable by the admin so the rates could be changed. Im far from a jQuery expert though and I love Drupal's ability to do powerful stuff without writing code. Thanks

2 Answers 2


I think what you're looking for is the Computed Field module to populate the field with the calculated value. For the rates table, you may have to write a custom module, create another content type, etc to manage it.

From the Computed Field project page:

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!


if you need an admin interface for this your best bet is to write a small module for it in PHP, not jQuery. Unless you want your "rates table" to be handled by nodes as well..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.