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

Question

Question

Automatically fill field based on selection

asked on November 2, 2018

I'm working on a paper requisition form and it has a table where you select the size of the paper being ordered from a dropdown and it fills in the unit price in another field.  It works fine on the initial row, but if I add a row to select more than one type of paper it doesn't work on the subsequent rows.  I'm sure I'm missing some kind of logic to tell it to do this per row, but I'm a javascript noob and haven't worked much with tables.

Here's the relevant piece of script:
 

    function pricefill() {
        if ($('.size select').val() == '8 1/2" x 11"') {
            $('.unitprice input').val("22.30")
        }
        if ($('.size select').val() == '8 1/2" x 14"') {
            $('.unitprice input').val("38.17")
        }
    }

I'm sure I could accomplish this using a lookup rule, but I was trying to avoid setting up a data source for a couple of paper sizes.

0 0

Answer

SELECTED ANSWER
replied on November 2, 2018

We made something similar by adding the "tbody tr" function in the javascript.

You have to add the "(this).find" before your field selector too.

Just replace the #q73 with your table selector.

Should look like something like this:

 


function pricefill() {
  $('#q73 tbody tr').each(function () {

     if ($(this).find('.size select').val() == '8 1/2" x 11"') {

         $(this).find('.unitprice input').val("22.30")

     }

     if ($(this).find('.size select').val() == '8 1/2" x 14"') {

         $(this).find('.unitprice input').val("38.17")

     }
 });
}

 

 

 

1 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.