I have problem in add new input:checkbox, when i adding new input and checked on it next setup clicked on button i not have value for input:checkbox that was checked. how is fix it?
DEMO: http://jsfiddle.net/G4QRp/
$(function () {
$('a.add_input').live('click', function (event) {
event.preventDefault();
var $class = '.' + $(this).closest('div.find_input').find('div').attr('class').split(" ")[0];
var size_un = $($class).length;
var $this = $(this),
$div = $this.closest($class),
$clone = $div.clone().hide().insertAfter($div).fadeIn('slow');
$clone.find('.adda').not(':has(.remove_input)').append('<div class="mediumCell"><a href="" class="remove_input"></a></div>');
$clone.find('input').val('').prop('checked', false);
$this.remove();
var size_un = $($class).length---1;
$($class + ':last input:checkbox').prop('name', 'checkbox_units[' + size_un + '][]');
console.log($($class + ':last input:checkbox').prop('name'));
});
});
Your code always clears the value of all the checkboxes it adds:
It’s working fine, though it’s quite confusing. The alert correctly shows the checkboxes that are checked, but since your code has set the value to ” for each of them, well, it’s empty. If you change it like this:
it shows the values to be the same as the original checkboxes.
You might want to think about using “data-” attributes instead of the “class” string for storing things like that “add_units” class name.