Created
May 16, 2016 15:42
-
-
Save mdailey77/28969f6c914368ab981a0a0471673f76 to your computer and use it in GitHub Desktop.
Populate one hidden form field with multiple checkbox answers using jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.customCheckboxesRow').each(function(){ | |
var checkboxVal = ''; | |
var checkboxel = $(this).find('.checkbox'); | |
// checks if checkbox was selected, if so, adds rel attribute value of each checkbox to checkboxVal variable | |
checkboxel.each(function(){ | |
if ($(this).hasClass('checkActive')){ | |
var selectedRel = $(this).attr("rel"); | |
checkboxVal += selectedRel + ', '; | |
} | |
}); | |
checkboxVal = checkboxVal.slice(0, -2); //removes trailing comma | |
$(this).children('input').val(checkboxVal); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks for sharing Matt. Try this:
$('.customCheckboxesRow').each(function(){$(".checkbox.checkActive[rel]", $ (this)).map(function() {
var compiled_rel =
return $(this).attr("rel");
}).get().join(", ");
});