• Xnau, I followd this support thread https://www.ads-software.com/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://www.ads-software.com/plugins/participants-database/

Viewing 1 replies (of 1 total)
  • Plugin Author xnau webdesign

    (@xnau)

    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.