2
votes

I have a three CCK fields: Quantity, Price and Total. I would like to compute Total as a Price * Quantity. Is there any way to achieve this when the user keys in the Price or Quantity the total should be calculated automatically. I also looked upon the computed field module but this works only when I have Price and Quantity and submit the form. I also don't have an idea of applying jQuery inside CCK fields in Drupal.

2

2 Answers

3
votes

Use the Computed field module for this.

Although it won't show the value on the node edit form, it will be automatically calculated and can be displayed in a view or in the node display.

Is there a particualr reason you want the total to be displayed on the node edit form? You can add some jQuery to automatically do this but you run the risk of the user changing this field or having JS disabled.

2
votes

Also there is an alternative to Computed field module for D7.

Math expression fields are dynamically updated via ajax on the entity form as soon as all necessary fields are populated. If JavaScript is disabled, the field will be evaluated when the form is submitted. The result is stored in the database when the form is submitted.

Math Field