I have web application with 2 radio buttons and 1 check box
Scenario : According to the radio button value, it should change check box checked status.
Html code
<div class="form-group">
<label>Is Main Meal</label>
<div class="radio">
<label>
<input type="radio" name="inputMeal" value="1" checked> Main Meal
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="inputMeal" value="0"> Sub Meal
</label>
</div>
</div>
<div class="form-group">
<div class="checkbox">
<label>
<input type="checkbox" name="chkIsPricing"> Is Pricing
</label>
</div>
</div>
Jquery Code
$('input[name="inputMeal"]').on('change', function () {
var val = $("input[name='inputMeal']:checked").val();
if (val == "0") {
$('input[name="chkIsPricing"]').attr('checked', true);
} else {
$('input[name="chkIsPricing"]').attr('checked', false);
}
});
This works well in first 2 clicks.
Step 1 : Click "sub meal" radio button and check box is set to checked status. (Success)
Step 2 : Click "main meal" radio button and check box is set to un-checked status (Success)
Step 3 : once again click "sub meal" radio button and check box remain as un-checked status. (Failed)
Whenever I click both radio buttons time to time, the check box remain as un-checked status. May I know where is the issue in my code? What I wonder is, in first two clicks (change the radio button) gives success scenario and after that check box is not changing according to the radio button value.
Additional Info
jQuery-2.1.4
HTML5