After selecting the check box, the check box values and the sum values are reset when the next page is passed. How should I modify it?
PHP code:
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td > <input name='amount' type='checkbox' value ='" . $row['amount'] . " ' onclick='totalIt()'></td>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['DATE'] . "</td>";
echo "<td>" . $row['amount'] . "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo " <input value='₩0' readonly='readonly' type='text' name='total' />";
// Free result set
mysqli_free_result($result);
JavaScript code:
function totalIt() {
var input = document.getElementsByName("amount");
var total = 0;
for (var i = 0; i < input.length; i++) {
if (input[i].checked) {
total += parseFloat(input[i].value);
}
}
document.getElementsByName("total")[0].value = "₩" + total;
}
and How can I check one more value in advance?
Aucun commentaire:
Enregistrer un commentaire