I'm trying to assign the value of a variable as true or false based on the selected checkbox. However, the code I have is not working as expected.
<input type="checkbox" id="chkBox1">
var chkBox1Val = $('#chkBox1').prop('checked') ? true : false;
How can I accurately get the value of the checkbox checked state and correctly assign it to a variable as either true or false?