Well, I have a foreach that loads several inputs, and I want my javascript code to read on all the inputs generated by foreach, can anyone give me a hint how to do it?
Example
<c:forEach items="${listaServico}" var="lista"
<input id="txt1" type="text" onkeyup="calcular()">
<input id="txt2" type="text" onkeyup="calcular()">
<input id="result" type="text"">
</c:forEach>
JAVASCRIPT
<script type="text/javascript">
function calcular(){
var valor1 = parseFloat(document.getElementById('txt1').value, 10);
var valor2 = parseFloat(document.getElementById('txt2').value, 10);
document.getElementById('result').value = valor1 * valor2;
}
</script>
It is to calculate the value of the first input and the second and throw in the third input.
The problem is that only loads JavaScript in the first item of forEach, the rest does not work JavaScript.
If anyone can help me, I would appreciate it.