So I have a script that will sum the values of checkboxes on my page, but I'm having trouble figuring out how to write an if/else if statement based on the value returned. I think the script would look something like this, but the fine folks on here seem to be pretty knowledgeable so any tips would be great!
Thanks in advance!
$(document).ready(function() {
function updateSum() {
var total = 0;
$(".sum:checked").each(function(i, n) {total += parseInt($(n).val());})
$("#total").val(total);
}
if (total == 0) {
"<input type="text" value="Great Job">";
else if (total == 3) {
"<input type="text" value="Good">";
else
"<input type="text" value="Ok">";
}
// run the update on every checkbox change and on startup
$("input.sum").change(updateSum);
updateSum();
})
Aucun commentaire:
Enregistrer un commentaire