javascript - How to differ inputs with same class? -


i have 1 button duplicates line choose more products. html:

<td>     <input type="hidden" class="cod_linha" name="cod_linha[]"style="width: 100%;" />     <input type="text" name="linha[]" class="linha" style="width: 100%;" /> </td> 

the problem is, have 2 functions find product , other fill fields want automatically, have differ filled field of empty field ? tried this:

var table = $('#tabelapedido'); $(table).each(function() { if($(this).find('input.linha').val()=== ''){      executes function fill fields , add new line. } else{ } 

and :

var counter = $(table).find("input.linha").length; for(var =0; < counter; i++){ if($(table).find('input.linha').eq(i).val()== ''{} 

but codes don't fill other empty line. see imagem :

enter image description here

my code fill fields :

function preenchercamposproduto(obj) {     var table = $('#tabelapedido');     $(table).each(function() {         if($(this).find('input.linha').val()=== '' &&                 $(this).find('input.ref').val()=== '' &&                 $(this).find('input.material').val()=== '' &&                 $(this).find('input.cor').val()=== '' &&                 $(this).find('input.descricao_marca').val()=== ''){     $.ajax({type: "post",         url: '/pedidoonline/index.php/pedidos/pesquisarcamposproduto',         async: false,         data: {             cd_cpl_tamanho: obj         },         datatype: 'json',         success: function(data) {             var linhaid = data[0].idlinha;             var linhalabel = data[0].labellinha;             var refid = data[0].idref;             var reflabel = data[0].labelref;             var corid = data[0].idcor;             var corlabel = data[0].labelcor;             var marcaid = data[0].idmarca;             var marcalabel = data[0].labelmarca;             var materialid = data[0].idmaterial;             var materiallabel = data[0].labelmaterial;`              var table = $('#tabelapedido');             $(table).each(function() {                 $(this).find('input.cod_linha').val(linhaid);                 $(this).find('input.linha').val(linhalabel);                 $(this).find('input.cod_ref').val(refid);                 $(this).find('input.ref').val(reflabel);                 $(this).find('input.cod_material').val(materialid);                 $(this).find('input.material').val(materiallabel);                 $(this).find('input.cod_cor').val(corid);                 $(this).find('input.cor').val(corlabel);                 $(this).find('input.id_marca').val(marcaid);                 $(this).find('input.descricao_marca').val(marcalabel);          });           }     });     chamaadicionarcampo();     }else{         console.log('entrei no else');     }     }); } 

thanks lot.

i've read code , wrote a sample code in jsfiddle, things writing about. in solution use css selector #tabelapedido tr:last select last added row, , write values fields in row.

hope helps.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -