I have an unknown number of input fields that have a class of "add", I just want to summarize them using jquery, I donβt know where I am mistaken.
<input name="add" class="add" type="text"> <input name="add" class="add" type="text"> <input name="add" class="add" type="text"> <input name="add" class="add" type="text"> <input type="button" value="" onClick="add()" />
`
function add(){ val = 0; $(".add").each(function() { str = (parseInt(this.value)) sum=str+str }); alert (sum) }
`
source share