Get value from a hidden field outside the php loop

1

Colleagues

I have a code in php that brings the value of the product from the bank.

<?php
...
while($jmMostrar = mysqli_fetch_object($sqlMostrar)){
      $mostrar = "<input type='hidden' id='produtos' name='valorProduto' value='".$jmMostrar->ValorProduto."'>";
}

Each $ jmShow-> Product Value brings a differentiated value. How would I get these values with jquery? I tried it that way, but it only brings me the first value:

$('.value-plus').on('click', function(){
var qtdCarrinho = $("#qtdCarrinho").val();
    
asked by anonymous 27.03.2017 / 22:58

1 answer

2

You can get it like this:

//NOME-DO-CAMPO-HIDDEN
$("input[name='valorProduto']").each(function(){
    if($(this).val() !== undefined){
      alert($(this).val());
    }
});
    
27.03.2017 / 23:01