javascript - Unable to uncheck checkbox from chrome -
i trying check/uncheck checkbox/radiobutton both table cell actual checkbox /radiobutton
i have written below code select checkbox/radiobutton table cell please refer code pen actuall code.
the code works fine ie 11 browser not in chrome. if select table cell checkbox selected in chrome when check on actual check box nothing happens .
i think checkbox internally calls propagatebelow method.
check/uncheck check box chrome(select on checkbox on table cell works fine)
<table border="1"> <tr> <td onclick="propagatebelow(this);" style="width:100px;"> <input type="checkbox" id="test" value="test123" /> </td> </tr> function propagatebelow(tablecell) { alert(tablecell); var radiobuttons = tablecell.getelementsbytagname('input'); (var = 0; < radiobuttons.length; i++) { var radiobutton = radiobuttons[i]; if (radiobutton != null && radiobutton != undefined) { if (radiobutton.type == 'radio' || radiobutton.type == 'checkbox') { radiobutton.click(); } } } }
not quite sure exact misbehavior you're observing. happens when test code when clicking cell, propagatebelow(this) called activates/deactivates checkbox, based on current state. when click checkbox, checkbox ticked, click event bubbles up, again triggering propagatebelow(this) in turn unticks checkbox again.
if want prevent that, have stop propagation of event when click on checkbox, like
<table border="1"> <tr> <td onclick="propagatebelow(this);" style="width:100px;"> <input type="checkbox" id="test" value="test123" onclick="cancelpropagation();" /> </td> </tr> </table> and implement cancelpropagation() follows
function cancelpropagation(ev){ var event = ev || window.event; event.stoppropagation(); return false; } here's modified codepen project: http://codepen.io/anon/pen/mwepxm
as mentioned, i'm not sure got mean. if doesn't help, let me know, i'll delete answer again :)
Comments
Post a Comment