Assign value to input

Asked

Viewed 37 times

1

I have this code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>    
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-maskmoney/3.0.2/jquery.maskMoney.min.js"></script>

<script>
$(function() {
  $('#Preco').maskMoney({ decimal: '.', thousands: ' ', precision: 2 });
})
</script>

$tabela1 .= '<td style="font-size: 12px"> <input type="text" name= "Preco['.$rows_cursos['IdRequisicao'].']" id= "Preco" value="0.00"></td>';

When the user uses the price column to enter the value, only the first row of the table works correctly, as shown in the image: inserir a descrição da imagem aqui

  • Attribute id of HTML must be unique on the page. It is the element identifier - as well as your CPF. Change your logic to something other than the id that might work.

1 answer

2


The problem is because the id is an attribute single there may only be 1, is replaced by the attribute class, works perfectly

<input type="text" name="" class="Preco">
<input type="text" name="" class="Preco">
<input type="text" name="" class="Preco">

<script>
    $(function() {
      $('.Preco').maskMoney({ decimal: '.', thousands: ' ', precision: 2 });
    })
</script>

Browser other questions tagged

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