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

Question

Question

How to populate my table with values from single line and select box fields

asked on September 18, 2019 Show version history

I have a table need to populate with the values filled in single line and selectbox when user click Add Row button and give that row serial no. in table, also if user need to delete row he will check delete checkbox column in table then click Delete Row button to delete the row selected. here is attached screenshot of my table and fields.

my problem is values add in all rows. I need to make a table display values that user had entered in the signle line and select box fields.

  $(".addRow").click(function(){
    var Item1 = $('#q1 input').val();
    var Item2 = $('#q2 input').val();
    var Item3 = $('#q3 select').val();
    $('#q8').click()                //table add button

    $('.Tbl tbody tr').each(function () {
      $(this).find('.tblItem1 input').each(function () {
        var tblItem1 = $(this).closest('tr').find('.tblItem1 input')
        var tblItem2 = $(this).closest('tr').find('.tblItem2 input');
        var tblItem3 = $(this).closest('tr').find('.tblItem2 select');
        tblItem1.val(Item1);
        tblItem2.val(Item2);
        tblItem3.val(Item3);

      });
    });
  });

 

 

0 0

Replies

replied on September 27, 2019 Show version history

I think this might be what you are looking for: 


  $(".addRow").click(function(){
    var Item1 = $('#q1 input').val();
    var Item2 = $('#q2 input').val();
    var Item3 = $('#q3 select').val();
    $('#q7').click()                //table add button

    $('.tblItem1 input').last().val(Item1); 
    $('.tblItem2 input').last().val(Item2); 
    $('.tblItem3 select').last().val(Item3); 

  }); 

 

It only updates the last items with class tblItem1, tblItem2, and tblItem3 - so as long as those class names are only used for those fields inside this one table, it should work fine.

 

Here it is with even less lines of code: 

$(".addRow").click(function(){
  $('#q7').click()                //table add button
  $('.tblItem1 input').last().val($('#q1 input').val()); 
  $('.tblItem2 input').last().val($('#q2 input').val()); 
  $('.tblItem3 select').last().val($('#q3 select').val()); 
}); 

 

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

Sign in to reply to this post.