I'll explain by putting the code:
In that part and where does my button add replicate my tr allowing to remove if necessary.
<script type="text/javascript">
$(function () {
function removeCampo() {
$(".removerCampo").unbind("click");
$(".removerCampo").bind("click", function () {
if($("tr.linhas").length > 1){
$(this).parent().parent().remove();
}
});
}
$(".adicionarCampo").click(function () {
novoCampo = $("tr.linhas:first").clone();
novoCampo.find("input").val("");
novoCampo.insertAfter("tr.linhas:last");
removeCampo();
});
});
</script>
In this second script and where clicking on my select and choosing an item it goes to the database and searches for information about the value of this item and returns it in the resultd class td
<script type="text/javascript">
function listanome(nome){
if(nome != ''){
var dados = {
listanome : nome
}
$.post('../BUSCAR_BANCO/busca_preco.php', dados, function(retorna){
$(".resultado2").html(retorna);
});
}else{
alert("Sem Equipamento Selecionado");
}
}
</script>
IN HTML THIS IS SO IN TR THAT IS REPLICATED AND IT RETURNS THE ITEM VALUE CONSULT:
<tr class="linhas">
<td colspan="4">
<select style="width:355px;" name="descricao[]" id="nome" onchange="listanome(this.value)">
<option value="">Selecione..</option>
<?php
include_once '../conexaobancodedados.php';
$sql = "select * from tabelapreco left outer join unidades on unidades.id_unidade = tabelapreco.id_unidade order by 'nome_tabela'";
$result= mysql_query($sql,$con);
if(@mysql_num_rows($result)>0){
while($row = mysql_fetch_array($result)){
?>
<option value="<?php echo $row["id_tabela"];?>"><?php echo $row["nome_tabela"];?> (<?php echo $row["nome_unidade"];?>)</option>
<?php
}
}else{
?>
<option value="">Sem Cadastro de Equipamento</option>
<?php
}
?>
</select>
</td>
<td><input type="number" style="width:50px;" size="1" name="qtd[]" id="qnt"></td>
<td class="resultado2"></td>
<td><input size="10" name="valortotal[]" id="total" onKeyPress="return(MascaraMoeda(this,'.',',',event))"></td>
<td><input size="10" name="royalties[]" onKeyPress="return(MascaraMoeda(this,'.',',',event))"></td>
<td><input size="6" name="imposto[]" onKeyPress="return(MascaraMoeda(this,'.',',',event))"></td>
<td><input size="16" name="transporte[]" onKeyPress="return(MascaraMoeda(this,'.',',',event))"></td>
<td><input size="11" name="desconto[]" onKeyPress="return(MascaraMoeda(this,'.',',',event))"></td>
<td><input size="16" name="valorfinal[]" onKeyPress="return(MascaraMoeda(this,'.',',',event))"></td>
<td><a href="#" class="removerCampo" title="Remover linha"><input type="button" name="Excluir" style="width:70px;background-color:red;"></a></td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="13">
<center><a href="#" class="adicionarCampo" title="Adicionar item"><input type="button" name="adicionar" value="Adicionar"></a></center>
</td>
</tr>
</tfoot>
The problem is that when doing the first select it brings me the return of the right value, being that when I click on add that creates the second line and I make the query of another item in the new select it brings the value to all the fields of the td class result2, since when replicating the line the name remains the same of that class.
Any ideas how to solve this? I am mt layman in javascript and just need to close it.