0
I need to change the fields inputs
of a GridView
, and as they are changed I must display the sum of these fields inputs
in one another input
which is at the bottom of the screen and the question is: how to get the value of these input fields through the JQuery
?
The HTML below was generated by GridView
and I don’t know how to get the ID
or NAME
of input
once they are created dynamically
<table id="gridModal">
<tbody>
<tr>
<td>Abril/2016</td>
<td>6</td>
<td>11,61</td>
<td>
<input id="gridModal_txtQtdNovo_0" type="text" value="11,61" name="gridModal$ctl02$txtQtdNovo">
</td>
<td>6</td>
</tr>
<tr>
<td>Maio/2016</td>
<td>23</td>
<td>44,52</td>
<td>
<input id="gridModal_txtQtdNovo_1" type="text" value="44,52" name="gridModal$ctl03$txtQtdNovo">
</td>
<td>21</td>
</tr>
<tr>
<td>Junho/2016</td>
<td>22</td>
<td>42,58</td>
<td>
<input id="gridModal_txtQtdNovo_2" type="text" value="42,58" name="gridModal$ctl04$txtQtdNovo">
</td>
<td>20</td>
</tr>
<tr>
<td>Julho/2016</td>
<td>21</td>
<td>40,65</td>
<td>
<input id="gridModal_txtQtdNovo_3" type="text" value="40,65" name="gridModal$ctl05$txtQtdNovo">
</td>
<td>19</td>
</tr>
<tr>
<td>Agosto/2016</td>
<td>23</td>
<td>44,52</td>
<td>
<input id="gridModal_txtQtdNovo_4" type="text" value="44,52" name="gridModal$ctl06$txtQtdNovo">
</td>
<td>21</td>
</tr>
</tbody>
</table>
This was the suggestion of DanielDutra
, as suggested in the comment below and met my needs, but the sum only calculates the whole part disregarding the fractional part:
<script type="text/javascript">
$(document).ready(function () {
var _valor = 0;
$("table#gridModal input").on('change', function () {
_valor += parseFloat($(this).val());
});
});
</script>
Do you need to pick up the value of each separate input? If not just get them all with one
$('table#gridModal input')
.– Daniel Dutra
yes separate, because as I change the value of the input I will make the sum with the others
– hard123