I have a "Song Request" form that counts every checkbox selected from each genre. The value is added to the "# SONGS PICKED" element that is fixed at the bottom of the website. It worked flawlessly, until I added Ninja Forms Conditional Logic: http://ift.tt/2sKe0Uw
As you select a genre from the "Choose your songs from the genres below:" select field, the corresponding checklist appears, and the previous one (if one is selected) is removed from the HTML.
This causes the counter to start back at 1 when you select a checkbox from the current/new checkbox list. If you switch back to the previous genre, it picks back up where that list was counted up to.
Below is my jQuery:
jQuery(document).ready(function() {
function updateCounter() {
var len = $("input[type='checkbox']:checked").length;
if (len > 0) {
$(".counter").text('' + len + '');
} else {
$(".counter").text('0');
}
if (len == 1) {
$(".multi").text('');
} else {
$(".multi").text('s');
}
}
jQuery(document).on("change","input[type='checkbox']", function() {
updateCounter();
});
});
I really can't figure out how to lock in the value. Any help would be greatly appreciated, as this site is 99.99% finished and needs this fixed before I can launch. Thank you ahead of time!
Aucun commentaire:
Enregistrer un commentaire