When I uncheck a checkbox, the text box value associated should be empty. And when I check again, need to display the previous value. Looking for a generic fix to save the previous values of the text boxes as the Checkbox count will increase in the future.
For Eg: When I check the first checkbox, the value of the text box associated is 1. When I uncheck the same checkbox, the value of the textbox should change to empty. And when I check it again, the old 1 value should display. Any help would be appreciated.
jQuery:
$(".drilling_specify").click(function () {
if ($(this).is(":checked")) {
$(this).nextAll('input').first().removeClass('hide');
} else {
$(this).nextAll('input').first().addClass('hide').val('');
}
});
HTML:
<input type="checkbox" class="drilling_specify" name="drilling_status[]" value="Accepted">
<span>Accepted</span>
<input type="text" class="hide" name="drilling_accpt_specify" value="1" />
<input type="checkbox" class="drilling_specify" name="drilling_status[]" value="Rejected">
<span>Rejected</span>
<input type="text" class="hide" name="drilling_accpt_specify" value="2" />
<input type="checkbox" class="drilling_specify" name="drilling_status[]" value="Hold">
<span>Hold</span>
<input type="text" class="hide" name="drilling_accpt_specify" value="3" />
CSS:
.hide{
display:none;
}