You are viewing limited content. For full access, please sign in.

Question

Question

Add two Fields Together that are Weighted?

asked on September 24, 2015 Show version history

I need some help calculating two input fields together that are weighted. We have a field with the CSS class of professionalSubtotal and a field with the CSS class of achievementSubtotal. The calculation needs to be as follows (.professionalSubtotal * .67)+(.achievementSubtotal * .33) = .teacherScore. The .teacherScore is the class name of the field the value needs to be placed in.

How would I go about creating that calculation using custom javascript in Forms?

1 0

Answer

SELECTED ANSWER
replied on September 24, 2015

Give the subtotal fields an additional CSS class named subtotal. Then you can use something like

$(document).ready(function () {
  
  $(document).on('blur change', '.subtotal input', calcscore);
  
  function calcscore() {
    var s = (parseNumber($('.professionalSubtotal input').val()) * .67) + (parseNumber($('.achievementSubtotal input').val()) * .33);
    $('.teacherScore input').val(s);
  }
  
  function parseNumber(n) {
    var f = parseFloat(n); //Convert to float number.
    return isNaN(f) ? 0 : f; //treat invalid input as 0;
  }
  
});
0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.