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

Question

Question

Clearing fields in one row with JavaScript

asked on March 20, 2017 Show version history
$(document).ready(function(){
  function clearout() {
    //$('.Tier').each(function(){$(this).find('option:first').attr('selected', 'selected')});
    //$('.Tier').find('option:first').attr('selected', 'selected');
    $('.Type').find('option:first').attr('selected', 'selected');
    $('.Code').each(function(){$(this).val("")});
    $('.UnitPrice').each(function(){$(this).val("")});
    $('.Quantity').each(function(){$(this).val("")});
    $('.LineTotal').each(function(){$(this).val("")});
  }
  
  function autofill() {
    $('.autofill').trigger('click');
  } 
  
  $('.Category').change(clearout);
  $('.Quantity').change(autofill);  
  
  $('.cf-table-add-row').click(function(){
    $('.Category').change(clearout);
      $('.Quantity').change(autofill);
  });
  
});
Hi, I want to make it so that if the user changes a certain field (Category), then all of the other fields in that row are blanked out.
Right now it works for all of the text fields, but I can't get it to work for only the one row, or for the drop downs. The second commented line clears the Tier properly but for all rows. The top line just doesn't work. The "each" lines clear but for every row, when I only want the current row.
0 0

Answer

SELECTED ANSWER
replied on March 20, 2017

Hi Brian,

Try this function (if Tier is a dropdown field while Code is a text field):

  function clearout() {
    $(this).closest('tr').find('.Tier select').val("");
    $(this).closest('tr').find('.Code input').val("");
  }

 

1 0
replied on March 21, 2017

Thank you very much!

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.