-1
I am starting the studies with pure Javascript, to practice better I created a table as if they were orders of a pizzeria, and put some field (flavor, quantity and value). At the end of the line I have a button "+". The idea is that when I click on it, add quantity to the field. For this, I imagined that it would be started this way at least to catch this field, but when I try to print it presents msg of undefined
:
//CAPTURA O BOTÃO +
var botaoSoma = document.querySelector(".btnSoma");
// CAPTURA A QUANTIDADE DA PIZZA
var calabresaQtd = document.querySelector("#quantidade_calabresa");
//ACRESCENTA UM EVENTO AO CLICAR NO BOTÃO + E IMPRIME A QUANTIDADE DE PIZZA
botaoSoma.addEventListener('click', function(){
alert(calabresaQtd.value);
});
Welcome Igor, I edited your question because we usually leave the texts as direct as possible, do not forget to do the [tour] to better understand how everything works here. Now about your question, would it be possible to add the HTML of the page? for this just use the [Edit] button just below the question.
– Barbetta
Put the HTML of the fields in question.
– Sam
Oops, thanks Barbetta, I’m starting to use the tool now, but I’ll adapt, thanks for the tips.
– StackOverflow2021
<table class="table"> <thead> <tr> <th>Flavour</th> <th>Quantity</th> <th>Value</th> </tr> </thead> <tbody> <tr> <td>Cababresa</td> <td id="quantity_calabresa">0</td> <td id="calabresa">8</td> <td> <button class="btn btn-Success btnSoma">+</button> <button class="btn btn-default">-</button> </td> </tr> </tbody> </table>
– StackOverflow2021