Assign value to input

1

I have this code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><scriptsrc="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:

    
asked by anonymous 27.07.2018 / 16:56

1 answer

2

The problem occurs because id is a single attribute and can only be 1 , if you replace with class attribute, 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>
    
27.07.2018 / 17:02