I have a html checkbox in my html form. Now, i want to assign 1 when it is checked and assign 0 when it is unchecked. So, how can i do that with jquery or java Script?
<!DOCTYPE html>
<html>
<script language="javascript" type="text/javascript">
<!--
function greeter() {
alert(document.getElementById(vehicleChkBox).value);
}
$('#vehicleChkBox').change(function(){
if($(this).attr('checked')){
$(this).val(1);
}else{
$(this).val(0);
}
});
</script>
<body>
<form>
<input type="checkbox" name="vehicle" id="vehicleChkBox" value="FALSE" />
<input type="submit" onsubmit="greeter()">
</form>
</body>
I tried with this. but, does not work.