Somando valores de vários inputs
HTML
<strong>HTML</strong>
<br />
<input type="text" value="100.20" class="input" />
<input type="text" value="200.20" class="input" />
<input type="text" value="300.20" class="input" />
<br><br>
Desconto:<br>
<input type="text" value="10.99" id="desconto" />
<input type="button" value="SOMAR" id="somar" />
<br /><br />
<strong>JQuery</strong>
<br />
Resultado: R$ <span class="resultado">0.00</span>
JavaScript
$("#somar").click(function(){
var total = 0;
var desconto = $("#desconto").val() != "" ? $("#desconto").val() : 0;
$('.input').each(function(){
var valor = Number($(this).val());
if (!isNaN(valor)) total += valor;
});
total = total - desconto;
$(".resultado").html(total.toFixed(2));
});
$( "#somar" ).trigger( "click" );