Title: Field calculation
Last modified: August 31, 2016

---

# Field calculation

 *  [samchief](https://wordpress.org/support/users/samchief/)
 * (@samchief)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/field-calculation-1/)
 * Xnau, I followd this support thread [https://wordpress.org/support/topic/update-only-one-field?replies=5](https://wordpress.org/support/topic/update-only-one-field?replies=5)
 * I have one field(balance) that should be calculated from the difference of two
   other fields (to_pay – amount_paid) (when the form is filled on the backend)
   
   SO i edited the code you provided in the thread and placed it in /templates/pdb-
   record-default.php line 8.
 *     ```
       <script type="text/javascript">
       // this is the standard wrappper for jQuery functions in WP
       jQuery(document).ready(function($) {
          // attach a function to the submit button click
          $('.pdb-record form .pdb-submit').click(function ()
          {
             // calculate the difference of two fields
             var difference = (parseInt($('input[name=to_pay]').val()) - parseInt($('input[name=amount_paid]').val()) );
             // set the value of the balance field
             $('input[name=balance]').val(difference);
             // now submit the data
             $('.pdb-record form').submit();
             // this is so the browser won't submit it also.
             return false;
          });
       });
       </script>
       ```
   
 * What am I not getting right here, is it the code or where(file or line) I should
   put it or anything else?
    Thank you.
 * [https://wordpress.org/plugins/participants-database/](https://wordpress.org/plugins/participants-database/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [Roland Barker](https://wordpress.org/support/users/xnau/)
 * (@xnau)
 * [10 years, 3 months ago](https://wordpress.org/support/topic/field-calculation-1/#post-7307016)
 * It’s a bit difficult to say with what you’ve got here. Looks like it might work,
   but it’s important to understand that the selectors in the script I provided 
   in that other thread might not work in your form.
 * The general method for debugging a script like this is first, make sure all of
   your selectors are correct. then make sure you are getting the correct values.
 * If you use the developer tools in Firefox, it’s pretty easy to debug a script
   like this, just use the debugger and insert breaks in the code where you can 
   inspect values.

Viewing 1 replies (of 1 total)

The topic ‘Field calculation’ is closed to new replies.

 * ![](https://ps.w.org/participants-database/assets/icon-256x256.jpg?rev=1389807)
 * [Participants Database](https://wordpress.org/plugins/participants-database/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/participants-database/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/participants-database/)
 * [Active Topics](https://wordpress.org/support/plugin/participants-database/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/participants-database/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/participants-database/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Roland Barker](https://wordpress.org/support/users/xnau/)
 * Last activity: [10 years, 3 months ago](https://wordpress.org/support/topic/field-calculation-1/#post-7307016)
 * Status: not resolved