<form id="form1" name="form1" method="post" action="">
<input type="checkbox" id="check1" value="radio" />
<label>left</label>
<input type="checkbox" id="check2" value="radio2" />
<label>right</label>
</form>
I would like to know if the checkbox is checked or not everytime someone clicks on it and then set a variable to the value yes.
if ($('#check1').attr('checked'); ){
var check1 = 'yes';
else
var check1 ='no'
}
this is what I have so far and it doesn’t work
How do I return the value
You don’t need an if-statement to do that. You can use
.is(":checked")which will returntrueif checked andfalseif not. Assign that value directly to your variable instead of using an if-statement: