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

Question

Question

Stopping Javascript affecting all rows on add new row button in Forms

asked on March 8, 2019

Hi there,

 

I'm having an issue implementing a field copy from two single line fields into two fields in my table.

The use case is that the customer inputs a job number and nominal number; these then get copied to the fields in the table, the columns job number and nominal number. This is because for 90% of the rows, these will be the same.

The issue I'm having is that on add new row, it should copy the job no and nominal again, which is fine and works. The issue is that if any values in the above rows have changed (which they might), the values get copied back up all the way and over write these fields. How can I target only the rows added by the "add new row" going forward? I presume it's something to do with the next tr but my tests haven't proven successful.

 

//add new row button click
$("#q20").on('click',function(){
    var jobNo=$('#Field6').val();
    $(".item_job input").val(jobNo);
  
   
   

    //without the lookup complete the value will be cleared when the jobNo lookup triggers
    $(document).on("lookupcomplete", function (event) {
      
     
   var nomNo=$('#Field12').val();
    $(".item_nom input").val(nomNo);
});

 

0 0

Replies

replied on March 8, 2019

The two easiest options might be

  1. Only change the value if the field is empty
  2. Only target the last row

 

Is this the complete code? It looks like you're missing brackets.

0 0
replied on March 8, 2019

yeah I missed out the last brackets.

 

What I've done is strip out all the Javascript and use calculations for my rows; then add a new third field in the database to match up these two fields and use that in my table to split up the lookup to prevent it interfering with the calculation when it's changed. It's actually quicker now and works well but there's no scope to change it. The issue I was having was really targeting the input of the same row rather than the input and I've tried differences of tr in my class code but never really seemed to work.

0 0
replied on March 8, 2019

Are you having trouble targeting specific rows with JavaScript, Calculations/Functions, or both?

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

Sign in to reply to this post.