I have a very large form, which has inputs and normal divs with the class "calcsum". The inputs are filled from the user, and the divs are result from calculations, which are done by a input button and a click() function.
I'd like now to sum up all inputs and divs, when they have value. But I cannot make the script to read all the values.
$('#calculate').click(function() {
var amount_sum = 0;
//calculate total worth of money
$('.calcsum').each(function(){;
console.log(Number($(this).val()));
amount_sum += Number($(this).val());
});
$('#amount_worth').html(amount_sum);
});
This is working with the normal input fields, but the values from the divs are ignored. I have tried several other ways with val() but none works. I do not understand why the values from the divs are ignored. Please help... :(
Here examples from the HTML:
<tr>
<td colspan="3">Bargeld</td>
<td><input type="text" name="cash" value="" id="amount_1" class="calcsum notice" title="Istwert eingeben"/></td>
<td><div class="style_calculated" id="nextam_1"></div></td>
</tr>
And here the div:
<tr>
<td colspan="2"><b>Bestandswert Gesamt:</b></td>
<td><input type="button" name="bestandswert" id="calculate_goods" value="Berechnen" /></td>
<td><div class="style_calculated calcsum" id="tradegoods" id="amount_14"></div></td>
<td><div class="style_calculated nextsum" id="next_tradegoods"></div></td>
</tr>
(The second field with next is not relevant at the moment, this comes later)
On the second html example, you can see that the div with tradegoods is the one missing. The value will be filled after pressing on "calculate_goods" .. do you need the example script also?