Skip to content

Instantly share code, notes, and snippets.

@sblmasta
Created February 7, 2015 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sblmasta/8938cdee8ffc127234df to your computer and use it in GitHub Desktop.
Save sblmasta/8938cdee8ffc127234df to your computer and use it in GitHub Desktop.
$(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