Do Calculations On Multiple Form Fields - jQuery AutoCalc

Do Calculations On Multiple Form Fields - jQuery AutoCalc

AutoCalc is a jQuery plugin created for the shopping cart of your online store that allows to dynamically calculate the values of your form fields similar to the Excel.

Supported formulas:

  • SUM: sums numbers
  • AVG: returns the average of the field values
  • MIN: returns the smallest value
  • MAX: returns the largest value
  • COUNT: counts all form fields
  • COUNTNOTEMPT: counts all non-empty fieldsĀ 

Supported operations:

  • add
  • subtract
  • multiply
  • divide
  • power

See also:

How to use it:

1. To get started, insert the jQuery AutoCalc plugin after jQuery library and we're ready to go.

<script src="" 
<script src="dist/jautocalc.js"></script>

2. Add formulas to your form fields using the jAutoCalc attribute as follows. Note that each form field must have an unique name.

<input type="text" name="qty" value="1">
<input type="text" name="price" value="9.99">
<input type="text" name="item_total" value="" jAutoCalc="{qty} * {price}">
<td><input type="text" name="total" value="" jAutoCalc="SUM({item_total})"></td>

3. Initialize the AutoCalc plugin and done.


4. Plugin's default options.

  // default attribute
  attribute: 'jAutoCalc',
  // thousand separator
  thousandOpts: [',', '.', ' '],
  // decimal separator
  decimalOpts: ['.', ','],
  // decimal places
  decimalPlaces: -1,
  // do the math right away?
  initFire: true,
  // allows chained calculation?
  chainFire: true,
  // do the math everytime keys are pressed
  keyEventsFire: false,
  // are the results read-only?
  readOnlyResults: true,
  // shows parse error
  showParseError: true,
  // treats empty as zero
  emptyAsZero: false,
  // smart intergers?
  smartIntegers: false,
  // callback
  onShowResult: null,
  // custom functions
  funcs: {},
  // custom constants
  vars: {}

This awesome jQuery plugin is developed by c17r. For more Advanced Usages, please check the demo page or visit the official website.

  • Publication date: 14.07.2018
  • Source