I ask for help, the task is to add all that in value with the class num. Problems arise if value is '-' or 'empty' instead of a number, then sum takes an empty value. How to make a conversion, so that if an invalid character is in value or a negative number, then they are converted to zero?
<table> <tr> <td> <input type='text' class='num' name='num1' value='2'> </td> <td> <input type='text' class='num' name='num1' value='3'> </td> <td> <input type='text' class='num' name='num1' value='-'> </td> </tr> var sum = 0; $('.num').each(function(){ sum += parseInt($(this).val()); }); console.log(sum);