jQuery function to get checkbox value if checked and remove value if unchecked.
example here
<input type="checkbox" id="check" value="3" />hiiii
<div id="show"></div>
function displayVals(){
var check = $('#check:checked').val();
$("#show").html(check);
}
var qqqq = window.setInterval( function(){
displayVals()
},
10
);
You don't need an interval, everytime someone changes the checkbox the change
event is fired, and inside the event handler you can change the HTML of #show
based on wether or not the checkbox was checked :
$('#check').on('change', function() {
var val = this.checked ? this.value : '';
$('#show').html(val);
});
FIDDLE
Working Demo http://jsfiddle.net/cse_tushar/HvKmE/5/
$(document).ready(function(){
$('#check').change(function(){
if($(this).prop('checked') === true){
$('#show').text($(this).attr('value'));
}else{
$('#show').text('');
}
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With