JSFiddle - React, Tailwind, and code Playground

by vrluckyin India

HTML

<input type="text" class="form-control" id="Preco0" name="produtosBonificacao[0].Preco" value="1" placeholder="Preço Sistema" readonly="readonly">

<input type="text" class="form-control" id="Preco1" name="produtosBonificacao[1].Preco" value="11" placeholder="Preço Sistema" readonly="readonly">

JavaScript

function subotal() {
   var sum = 0.0;
   //1. get input elements whose name starts with "produtosBonificacao"
  
   $('input[name^="produtosBonificacao"]').each(function () {
        //2. Make sure that input belongs to "Preco" property
   	    if($(this).attr('name').indexOf('.Preco')>-1)
        {
           //3. Parse value, for this example just use parseInt
           //Make sure that you don't need parseFloat.
           //Before using parsed value into sum, just make sure that it is valid number.
           var price = parseInt($(this).val());
           sum += (isNaN(price)?0: price);
        }
    });
    //I need to set the sum in readonly input. 
	alert(sum);
}
$(document).ready(function(){
subotal();

})