javascript get the value of checkbox if checked without button clicked
I am struck in the middle of project, please help..
how to get the check box value from the class name or from by name or by id through alert so that the particular value I can pass...
I am sorry to ask..I am new the jquery and javascript..
This is my HTML ...
<input type="checkbox" name='cbox' value="red" class="theClass"/>red
<input type="checkbox" name='cbox' value="green" class="theClass"/>green
<input type="checkbox" name='cbox' value="yer" class="theClass"/>yer
<input type="checkbox" name='cbox' value="asdasd" class="theClass"/>asdasd
<input type="checkbox" name='cbox' value="radgdfged" class="theClass"/>radgdfged
$(function(){
$('input[type=checkbox]').on('change', function() {
alert($(this).val());
console.log($(this).val());
});
});
I googled much ...but every where onclick the button than only will get all checkbox values.. I am getting the values using the onclick button ....but the thing is getting the value without using the button... My concern is getting the value if checkbox is checked..
eg: if i checked red , i should get alert 'red'.....
<script type="text/javascript"> [CODE] </script>nodes