javascript - Checkbox is still showing true when unchecked jQuery -
javascript - Checkbox is still showing true when unchecked jQuery -
ok, i'm having issue $.prop('checked') functionality. when unchecking of boxes, , using function read checkboxes, of them still showing true when of them should showing unchecked. part of function checks below, background: i'm using table input values in each td element , due way it's written, i'm having gather info / validate / , check using td.each() function.
$("td", ele).each(function(idx){ var before = $('.e_content', this), b_name = $('input:last[type!="hidden"], textarea:last, checkbox:last, select:last', this).attr('name'), b_val = $('input[name="'+b_name+'"], select:last, textarea[name="'+b_name+'"]', this).val(), b_chx = $('input:checkbox[name="'+b_name+'"]', this).prop('checked'), after = function(){ before.hide(); $(ele).css("background", color); $('td.edit', ele).show(); $('td.save', ele).hide(); $('span', this) // working on taking value of .e_content form , replacing span .html(function(){ console.log(b_name+' : '+b_chx); if(b_val != undefined && b_val != ''){ if(b_name == 'stagetype'){ if(b_val == 1){ homecoming 'voice'; } if(b_val == 2){ homecoming 'text'; } if(b_val == 3){ homecoming 'email'; } } else if(b_name == 'qtrhour') { homecoming $('select', before).find(':selected').text(); } else if(b_chx == true) { homecoming '✓'; } else if(b_chx == false) { homecoming '✗'; } else { if(before.find('input:last').prop('type') != 'checkbox') homecoming b_val.replace(/\n\r?/g, '<br />'); } } }) .show(); }; $(this).html(after); });
the problem line:
b_chx = $('input:checkbox[name="'+b_name+'"]', this).prop('checked'),
it's coming true when checkbox has been unchecked before save button hit. function fires on .save click event. plenty determine might going wrong.
you can seek following,
$('input:checkbox[name="'+b_name+'"]', this).is(':checked');
javascript jquery checkbox
Comments
Post a Comment