I have 2 checkboxes positioned in 2 different places on same page.
And, I am using the following code to append the checked values.
var checkboxes = $("#sercuisineslist input[type='checkbox'],#sercuisineslist2 input[type='checkbox']");
function docheck(){
$('#myquery').val(
checkboxes.filter(':checked').map(function(item) {
return this.value;
}).get().join(', ')
);
}
checkboxes.on('change', function() {
docheck();
});
When I check the same checkbox in 2 different areas then the same value is getting appended twice but this is never an issue in my scenario. But when I uncheck the checkboxes, I need to uncheck in both the areas so to ensure that appened value will be remove twice.
For example if African is checked the the textbox myquery shows as
African, African
And when I uncheck how can I ensure African is removed twice rather than once?
I tried something like
checkboxes.on('uncheck', function() {
docheck();
docheck();
});
and this didn't help me.
Aucun commentaire:
Enregistrer un commentaire