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

Question

Question

How to set field value based on table cell changed value

asked on January 6, 2019

I have two input fields with label empID and Name with calsses empID and Name, also has a table with class tbl1 that has 3 columns tblempID, tblName and tblTxt with calsses tblempID, tblName, tblTxt. How to set empID field value to be the same tblmpID value when any tblTxt cell value changed in each row in table.

T tried the following:

 

$(document).ready(function(){
 tblTxtchange();
  
  $('.tbl1').on('change', tblTextchange);
  
  function tblTxtchange() {
    $('.tbl1 tbody tr').each(function () {
      $(this).find('.tblTxt').each(function () {
        $('.tblTxt').change(function(){           
          $('.empID').val($('.tblText')
          .closest('tr').find($('.tblEmpID').val()));
        });
      });
    });
  }

});
1.PNG
2.PNG
1.PNG (1.18 KB)
2.PNG (6.09 KB)
0 0

Answer

SELECTED ANSWER
replied on January 6, 2019

Dear Mahmoud,

 

please try the following will work.

$(document).ready(function(){
  
  $('.tbl1 tbody').on('change','.tblText input',function(){
  
  $('.empID input').val($(this).closest('tr').find('.tblEmpID input').val());
  
});
});

Regards,

Maher.

0 0
replied on January 6, 2019

 

Unfortunately, not working :(

0 0
replied on January 6, 2019

did you check all the classes written correctly ?

i just try it myself and it is working.

please make sure that the classes are written correctly.

and remove any old code and use the one i posted as it is.

i am 100% sure it will work.

awaiting your reply.

 

Regards,

1 0
replied on January 7, 2019

Yes, there was one class not correct i wrote it tblTxt and in your code was tblText.

Thank You very much.

0 0
replied on January 8, 2019 Show version history

Sorry, again I need a help.

Now I need to do some actions when "empID" value changes.

I try the following but it not working, i think because it filled by jquery so it can not see field value changes.

$('.empID input').change(function(){

alert($('.empID input').val());

});

 

0 0
replied on January 8, 2019

hi mahmoud

just add the following to the code after changing the value of empID:

 

$('.empID input').trigger("change");

 

Regards,

Maher.

0 0
replied on January 9, 2019

I Already tried this also, but it do action two times if table has more the one row, I think the reason is using trigger so code working two times, that's why i use .change(), But also not working.

Sorry for disturb :( .

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.