Created
February 7, 2015 13:14
-
-
Save sblmasta/8938cdee8ffc127234df to your computer and use it in GitHub Desktop.
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
$(function(){ | |
$('.arrayToString input[type="checkbox"]').on('click', function(){ | |
var t = $(this); | |
var inputData = $('#' + t.data('input')); | |
var list = inputData.val().split(',').filter(function() { return true; }); | |
var value = t.val(); | |
var elem = list.indexOf(value); | |
if( $(this).prop('checked') ) | |
{ | |
//wstrzykniecie wartosci checkboxa do listy (tablica) | |
list.push(value); | |
} | |
else | |
{ | |
if( elem > -1 ) | |
{ | |
//usuniecie elementu tablicy jesli istnieje | |
list.splice(elem, 1); | |
} | |
} | |
inputData.val(list.join(',')); | |
console.debug(list); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment