in my mvc application i have a checkbox. but dont know why its value is always true. pls help
my view page
<div id="maindiv">
<%: Html.CheckBoxFor(m => m.status)%>
<%: Html.LabelFor(m => m.status)%>
</div>
and the script is here how i am getting the value TRUE always
<script type="text/javascript">
$('#status').change(function () {
alert(" active " + $('#status').val());
});
</script>
use instead:
Explanation:
you were reading the value of the checkbox which is always true, you need to check whether its
checked attributeis checked or unchecked.I used the ternary operator to check check whether it’s checked or not
You could have also used
$("#status").is(":checked")but it is slower.