checkbox problem
checkbox problem
hi
i have a series of checkbox in my page, each one has its own value. i want to return this value when user click on eachbox, plus ststaus of checkbox (checked/unchecked).
i wrote this code, but it always return first checkbox value:
- cb1: <input name="cb[]" type="checkbox" value="1" class="cb-compare" id="cb-compare-1"><br>
cb3: <input name="cb[]" type="checkbox" value="2" class="cb-compare" id="cb-compare-2"><br>
cb3: <input name="cb[]" type="checkbox" value="3" class="cb-compare" id="cb-compare-3"><br>
<SCRIPT language="Javascript" type="text/javascript" src="jquery.js"></SCRIPT>
<script type="text/javascript">
$(document).ready( function() {
var $cbc = $('.cb-compare');
$cbc.click(function(){
if ($cbc.attr('checked')) {
alert("checked-"+$cbc.attr('value'));
}else{
alert("unchecked-"+$cbc.attr('value'));
}
})
})
</script>