I have the following code,
...
<input type="hidden" name="unchecked" id="unchecked" value="" />
<?php
$ind = 1;
foreach($array as $v){
?>
<input class="checkbox checked" id="checked_<?php echo $ind; ?>" type="checkbox" value="<?php echo $value['id']; ?>"/>
<?php
$ind++;
}
?>
...
I want to store checkbox values as comma seperated in hidden box. so i tried with the following jquery ,
<script type="text/javascript">
$(function(){
$("input.checked").click(function(){
//alert($(this).val());
$("input#unchecked").val($.map($("input[id^='checked_']"), function( item ) {
return $(item).val();
}).join(","));
});
});
</script>
The above script stores all values of checkbox when i click any one of check box. what i done wrong on this. kindly advice
Change
to
Or use the below:
Select the checked:
$("input[id^='checked_']").is(':checked')Select the unchecked:
$("input[id^='checked_']").not(':checked')