Pick up value from a Hidden field outside the php loop

Asked

Viewed 159 times

1

Colleagues

I have a php code 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 $jmMostrar->Valuemove brings a different value. How would I get these values with jquery? I tried that way, but it only brings me the first value:

$('.value-plus').on('click', function(){
var qtdCarrinho = $("#qtdCarrinho").val();
  • Fox inside the while you don’t want to make a concatenation ($mostrar .= "...) or is that what you really want?

  • Hello Miguel. Actually it is already concatenated. I put here as an example. I need to take the product value and play inside a jquery outside the PHP loop.

  • Ha ok I realized, in this case I think you already have the answer of @Alison who does it. BUT a lot of attention should not have repeated ids in the DOM... My suggestion is to switch to class

1 answer

2


You can catch it like this:

//NOME-DO-CAMPO-HIDDEN
$("input[name='valorProduto']").each(function(){
    if($(this).val() !== undefined){
      alert($(this).val());
    }
});
  • Hello Alisson. Unfortunately it didn’t work.

  • @Fox.11 returns what on Alert ?

  • @Fox.11 changed the code, try it there

  • worked yes, but when it has 02 values, it returns 03 being the latter as undefined...

  • @Fox.11 placed a check

  • perfect.. worked... Thank you very much!

  • I can only accept your reply in 03 minutes, but I will return to accept. rs rs thank you!

  • 1

    Thank you @Fox.11

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.