I want to confirm when someone unchecks a checkbox. The following function only works every other time. When it first loads its fine. It calls the confirm and if you cancel it leaves the checkbox checked. But if you click it again nothing happens. I'm sure it something simple that I'm missing:
$scope.check = function(clickedid) {
if (document.getElementById(clickedid).checked === true) {
return false;
} else {
var box= confirm("Are you sure you want to do this?");
if (box===true){ // yes sure
return true;
}
else{ // cancel
document.getElementById(clickedid).checked = true;
}
}
};
and here is the html
<lable>Checkbox
<input type="checkbox" id="check1" ng-model="active" ng-change="check('check1')">
</label>
Here is a jsfiddle
Aucun commentaire:
Enregistrer un commentaire