2
I have a div with 3 inputs (value, aliquot, total value) they are inside a clone div in jquery... I can calculate through id as in the code below, but since it is cloned in jquery only works in the main div because it cannot have duplicate id..
I thought I’d take the input by name, but I haven’t been able to yet...
Note that by clicking "CLONE" the div it only works in the original div, not in the cloned..
//Função que calcula os Inputs pelo ID
function Calc(){
ValorUm = parseFloat(document.getElementById('valor').value);
ValorDois = parseFloat(document.getElementById('aliquota').value);
document.getElementById('valortotal').value = (ValorUm*ValorDois/100).toFixed(2);
}
//Função clone
$(document).ready(function() {
var linha = $(".engloba:first").clone();
$("#mais").click(function() {
$("#conteudo_engloba").append(linha.clone());
});
});
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.2.min.js"></script>
<form>
<input type="button" name="" value="CLONAR" id="mais">
</form>
<div id="conteudo_engloba">
<div class="engloba">
<h1>Conteudo</h1>
Valor <input type="text" id="valor">
Aliquota <input type="text" id="aliquota" onblur="Calc()">
Valor Total <input type="text" id="valortotal">
</div>
</div>
Dwarf Car understood your explanation... Why you clone?
– KhaosDoctor
Khaosdoctor, friend, see that you have the "CLONE" button that makes a copy of the current div and creates another div...
– Alh