I have already look and applied lots of the solution methods on web i.e. Check/Uncheck checkbox with javascript? but my problem is make the checkbox to be checked after page load. I use $(window).load(function () and $(document).ready(function () but none of them working. However, if I can set checked property in html of checkbox the problem will be solved. But I cannot set this property via a Javascript variable. I also tried by jQuery but the problem is related to setting this property after rendering of checkbox. Any idea to fix the problem?
<input type="checkbox" class="form-check-input" id="chkAll" >
//Although the checkboz is already rendered at this stage I cannot set it
$(window).load(function () {
if (@Html.Raw(Json.Encode(ViewBag.IsAll))) {
document.getElementById("chkAll").checked = true;
}
});
and
//As the checkbox is not rendering during page load this method is useless
$(document).ready(function () {
if (@Html.Raw(Json.Encode(ViewBag.IsAll))) {
document.getElementById("chkAll").checked = true;
}
});
Aucun commentaire:
Enregistrer un commentaire