Title: Automatic Total Option?
Last modified: August 31, 2016

---

# Automatic Total Option?

 *  Resolved [ztaylor39](https://wordpress.org/support/users/ztaylor39/)
 * (@ztaylor39)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/automatic-total-option/)
 * Hi,
 * I’ve got a form on this [site](http://shawnlemon.com/support-agreement2/) below
   allowing visitors to sign up for different products in a create-your-own plan
   type of thing.
    Each item costs a different amount and the visitors can add whichever
   they want. My last field on the form is a “Total”, is there a way to get it to
   automatically display the sum of the prices of the selected form options?
 * Thanks in advance,
    ZTaylor
 * [http://shawnlemon.com/support-agreement2/](http://shawnlemon.com/support-agreement2/)
 * [https://wordpress.org/plugins/cforms2/](https://wordpress.org/plugins/cforms2/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [bgermann](https://wordpress.org/support/users/bgermann/)
 * (@bgermann)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/automatic-total-option/#post-7231929)
 * There is a way, but not a built-in way. You would have to write some JavaScript
   that listens on the items’ onchange events. On each event you would sum up the
   fields’ values and replace the Total value.
 *  Thread Starter [ztaylor39](https://wordpress.org/support/users/ztaylor39/)
 * (@ztaylor39)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/automatic-total-option/#post-7231973)
 * Excellent!!
 * I’m fairly new to JS though… How would I go about writing a script to sum the
   values using an onchange event?
 *  Plugin Author [bgermann](https://wordpress.org/support/users/bgermann/)
 * (@bgermann)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/automatic-total-option/#post-7231988)
 * With jQuery, which is included in WordPress, so you do not have to load it additionally,
   the core lines would look like
 *     ```
       var offsets = [11,12,15,16,17];
   
       var changehandler = function () {
         var sum = 0;
         for (var i = 0; i < offsets.length; i++) {
           sum += jQuery('#cf_field_' + offsets[i]).val();
         }
         jQuery('#cf_field_19').val(sum);
       };
   
       for (var i = 0; i < offsets.length; i++) {
         jQuery('#cf_field_' + offsets[i]).change(changehandler);
       }
       ```
   
 *  Thread Starter [ztaylor39](https://wordpress.org/support/users/ztaylor39/)
 * (@ztaylor39)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/automatic-total-option/#post-7231996)
 * Awesome!
 * Where exactly do I put that code?
 *  Plugin Author [bgermann](https://wordpress.org/support/users/bgermann/)
 * (@bgermann)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/automatic-total-option/#post-7232017)
 * An ugly solution is just to paste it in one of the field’s titles, surrounded
   by <script>…</script> tags. There are better solutions, like loading it in a *.
   js file on exactly that page, but you would have to figure it out by yourself
   or search the web.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Automatic Total Option?’ is closed to new replies.

 * ![](https://ps.w.org/cforms2/assets/icon-128x128.png?rev=1010031)
 * [cformsII](https://wordpress.org/plugins/cforms2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cforms2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cforms2/)
 * [Active Topics](https://wordpress.org/support/plugin/cforms2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cforms2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cforms2/reviews/)

## Tags

 * [add](https://wordpress.org/support/topic-tag/add/)
 * [sign-up](https://wordpress.org/support/topic-tag/sign-up/)
 * [sum](https://wordpress.org/support/topic-tag/sum/)

 * 5 replies
 * 2 participants
 * Last reply from: [bgermann](https://wordpress.org/support/users/bgermann/)
 * Last activity: [10 years, 1 month ago](https://wordpress.org/support/topic/automatic-total-option/#post-7232017)
 * Status: resolved