Press "Enter" to skip to content

jQuery Plugin Calculates Equations Using Form Input Fields | AutoCalc

AutoCalc is a jQuery plugin created for your online store’s shopping cart that allows you to dynamically calculate form field values similar to Excel.

A plugin to automate and simplify “fast” mathematical operations. The simplest use is to set the attribute jsAutoCalc = “” on the input text tag and call $ (“*”). jAutoCalc ();.

Supported:

  • SUM: Adds numbers
  • AVG: Returns the average of field values
  • MIN: Returns the smallest value
  • MAX: Returns the largest value
  • COUNT: Counts all form fields
  • COUNTNOTEMPT: Counts all non-blank fields

How to make use of it:

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

<script src="/path/to/cdn/jquery.slim.min.js"></script>
<script src="dist/jautocalc.js"></script>

2. Add formulas to the form fields using the jAutoCalc attribute as follows. Note that each form field must have a 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 you’re done.

$('form').jAutoCalc();

4. The default options for the plugin.

$('form').jAutoCalc({

  // 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: {}
  
});

Do Calculations On Multiple Form Fields, jQuery AutoCalc Plugin/Github


See Demo And Download

Official Website(c17r): Click Here

This superior jQuery/javascript plugin is developed by c17r. For extra Advanced Usages, please go to the official website.

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *