0
I’m a beginner in HTML and Javascript and I’m caught in a problem for a college project. Basically I have an e-commerce without BD, so the products are defined in HTML.
My problem is that by clicking the add button to the cart, it does not differentiate the products and ends up adding only the first product.
<div class="container-fluid">
<!-- Essa class row que é a linha que eu falei-->
<div class="row">
<div class="col-md-3 col-xs-3" id="Fonte">
<fieldset>
<legend class="prod">Fonte Corsair 400w</legend>
<img src="imagens/Fonte/fonte-corsair-vs400-80plus-white-pfc-ativo-400w-cp-9020117-la-1502453690.jpg" id="foto">
<p>R$: </p><p input type="number" id="txtValor">229.90</p>
<p>
Quantidade<br>
<input type="number" id="txtQtde" min="1" max="5" oninput="calcTotal();">
</p>
<button type="add" class="btn btn-primary btGravar">
Adicionar
<i class="fas fa-plus"></i>
</button>
</fieldset>
</div>
<div class="col-md-3 col-xs-3" id="pv1060">
<fieldset>
<legend class="prod">GTX 1060 3GB</legend>
<img src="imagens/Placa_de_video/placa-de-video-geforce-galax-gtx-1060-oc-3gb-60nnh7dsl9c3-gddr5-pci-exp_33631.jpg" id="foto">
<p id="txtValor">
R$ 1349,90
</p>
<p>
Quantidade<br>
<input type="number" id="txtQtde" min="1" max="5" oninput="calcTotal();">
</p>
<button type="add" class="btn btn-primary btGravar">
Adicionar
<i class="fas fa-plus"></i>
</button>
</fieldset>
</div>
</section>
Javascript
$(".btGravar").on('click', function(){
var produto = $('.prod').html();
var quantidade = document.getElementById("txtQtde").value;
var orçamento = $('#txtValor').html();
var valor = orçamento * quantidade;
var adicionar = '<tr><td>' + produto + '</td><td>' + quantidade +'</td><td>' + valor + '</td><td><button class="btn btn-danger btApagar"><span class="glyphicon glyphicon-trash"></span>Apagar</button></td></tr>';
$(".tb0").prepend(adicionar);
$("#shopCart").modal("show");
}
)
You have two classes with the same name
– adventistaam
Managed to solve?
– Sam