I have a few checkbox
in a form and I'm setting each value if its checked
or unchecked
. So a checkbox that is checked
has a value of TRUE
and unchecked as FALSE
If I have all of the checkbox checked(value is TRUE
) and I unchecked one of them, the other checkbox also unchecked and the value on the database also become FALSE
. I can't understand the behavior below is my code
HTML
<label><input type="checkbox" id="trans_val_identical" value="FALSE">II Transaction Value of Identical Goods</label>
<label><input type="checkbox" id="trans_val_identical" checked="checked" value="FALSE">II Transaction Value of Identical Goods</label>
</div>
<div class="checkbox">
<label><input type="checkbox" id="trans_val_similar" value="FALSE">III Transaction Value of Similar Goods</label>
<label><input type="checkbox" id="trans_val_similar" checked="checked" value="FALSE">III Transaction Value of Similar Goods</label>
</div>
<div class="checkbox">
<label><input type="checkbox" id="deductive_val" value="FALSE">IV Deductive Value</label>
<label><input type="checkbox" id="deductive_val" checked="checked" value="FALSE">IV Deductive Value</label>
</div>
<div class="checkbox">
<label><input type="checkbox" id="computed_val" value="FALSE">V Computed Value</label>
<label><input type="checkbox" id="computed_val" checked="checked" value="FALSE">V Computed Value</label>
</div>
<div class="checkbox">
<label><input type="checkbox" id="fallback_val" value="FALSE">VI Fallback Value</label>
<label><input type="checkbox" id="fallback_val" checked="checked" value="FALSE">VI Fallback Value</label>
JS
$('#trans_val_identical').change(function(){
if($(this).attr('checked')){
$(this).val('TRUE');
}else{
$(this).val('FALSE');
}
});
$('#trans_val_similar').change(function(){
if($(this).attr('checked')){
$(this).val('TRUE');
}else{
$(this).val('FALSE');
}
});
$('#deductive_val').change(function(){
if($(this).attr('checked')){
$(this).val('TRUE');
}else{
$(this).val('FALSE');
}
});
$('#computed_val').change(function(){
if($(this).attr('checked')){
$(this).val('TRUE');
}else{
$(this).val('FALSE');
}
});
$('#fallback_val').change(function(){
if($(this).attr('checked')){
$(this).val('TRUE');
}else{
$(this).val('FALSE');
}
});
Aucun commentaire:
Enregistrer un commentaire