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

Question

Question

Need Help Multiplying Against a Drop Down

asked on November 14, 2014 Show version history

I am working on a Travel Reimbursement Request form that allows a user to enter a per diem rate, number of days, 75% amount, and a "Multiply 75% by". There is then a Meal Total field that displays the final result.

Currently, the "Per Diem" amount is multiplied by the "Number of Days" value and the result shows in the Meal Total. What I cannot figure out is how to then take the "75% for First and Last Day" and multiple by the number that is chosen from the "Multiply 75% by" drop down. Any help would be greatly appreciated.

1 0

Answer

SELECTED ANSWER
replied on November 17, 2014

You still need the "select" bit in the jQuery selector. You may also need to wrap the whole thing in your parseNumber function, too. This should work:

var s = parseNumber($('#q51 select').val());

 

0 0

Replies

replied on November 17, 2014

You should be able to get the information you want if you assign numeric values to each choice in your drop down from the Form Edit page. The Javascript you need to reference the value is slightly different than for a single line field:

$('.Dropdown_Class select').val()

You could reference the field by it's ID also, if you used the '#qN' format in the selector. Finally, you may need to wrap the whole thing in a parseInt() or parseFloat() function to explicitly convert text into a numeric format. Hopefully that's enough to point you in the right direction.

0 0
replied on November 17, 2014

This is what I came up with based on your feed back, but the 75perdiemtotal is coming out as 0. #q51 is the field id of the dropdown field. The drop down field does have values specified (1 and 2).

//Calculate 75% Per Diem subtotal
  $('.75perdiemsum').on('blur change', 'input', perdiem75sumtotal);
    function perdiem75sumtotal() {
        var s = $('#q51').val();
        $('.75perdiemsum input').each(function () {
            s *= parseNumber($(this).val());
        });
        $('.75perdiemtotal input').val(s);
    }
    function parseNumber(n) {
        var f = parseFloat(n); //Convert to float number.
        return isNaN(f) ? 0 : f; //treat invalid input as 0;
    }
  //end calculate 75% Per Diem subtotal

 

0 0
replied on June 1, 2016

Blake, see if this will help.  I added a classname for the dropdown selector (.multiplier), and you may need to replicate this the other way so if someone changes the dropdown last it does the same thing in a reverse order, but this seems to work:


    $('.75perdiemsum').on('change blur', 'input', perdiem75sumtotal);
      function perdiem75sumtotal() {
      var s = parseNumber($('#Field14 option:selected').val());
        $('.75perdiemsum input').each(function () {
             s *= parseNumber($(this).val());
            t = parseNumber(s);
       
            $(".75perdiemtotal input").val(t);
     });
                                
    function parseNumber(n) {
        var f = parseFloat(n); //Convert to float number.
        return isNaN(f) ? 0 : f; //treat invalid input as 0;
     
        }   
    }
  

0 0
replied on June 1, 2016

Field14 was my dropdown, but if you use the classname you could put that there.

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

Sign in to reply to this post.