This is a Datalist in my code.
<asp:DataList runat="server" ID="dlstate" RepeatColumns="6">
<ItemTemplate>
<asp:CheckBox runat="server" ID="chk" Text='<%#Eval("area_state") %>' OnCheckedChanged="chk_state_SelectedIndexChanged" onchange="return checkconfirm(this);" AutoPostBack="true" />
</ItemTemplate>
</asp:DataList>
This is the Javascript code.
<script type="text/javascript">
function checkconfirm(a) {
if (a.checked == true) {
return true;
}
else {
debugger;
var box = confirm("Are you sure you want to unselect this state as areas alloted under this state will be lost?");
if (box == true)
return true;
else {
a.checked = true;
return false;
}
}
}
</script>
The problem is that when this apsx page is rendered in html the onchange="return checkconfirm(this);" appears on a span rather than the checkbox. I have tried several ways for confirmation and yet I am not able to put the onchange event on the checkbox.
onchangewithOnClick