I am trying to change the name to null/empty of all checkboxes which is unchecked on onchange event and on ondocumentready event using jquery.
this is my code
<div id="tab_4">
<div class="col-xs-12">
<input type="text" name="txtbox1" value="1">
<input type="checkbox" name="chkbox1" value="1">
<input checked type="checkbox" name="chkbox2" value="2">
<input type="checkbox" name="chkbox3" value="3">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$('#tab_4 input[type=checkbox]').each(function(i){
if($(i).not(':checked'))
{
$(this).attr('name', '');
}
});
});
$('#tab_4 input[type=checkbox]').change(function(){
$('#tab_4 input[type=checkbox]').each(function(i){
if($(i).not(':checked'))
{
$(this).attr('name', '');
}
});
});
</script>
But it makes all name attribute to null even checked ones.
I used this answer Changing input name using JQUERY