Select Checkbox List on page load event using Javascript

Select Checkbox List on page load event using Javascript

Introduction : This Example used to select checkbox list values when the user can edit the page data
when user can click on edit button it is also need to display selected checkbox value here i am explain using jquery with simple Example.


Step 1: Html Page

<html>
<body>

<input id="aaa" type="checkbox" name="aaa" value="aaa" /> aaa<br />
<input id="bbb" type="checkbox" name="bbb" value="bbb" /> bbb <br />
<input id="ccc" type="checkbox" name="ccc" value="ccc" /> ccc

</body>
</html>

Step 2: Java script code

<script src="~/Scripts/jquery-1.7.1.js"></script>
<script src="/Scripts/jquery-1.7.1.min.js"></script>

<script>
    $(document).ready(function () {
        var str = "aaa,bbb,ccc";
        var array = str.split(",");
        for (var i = 0; i < array.length; i++) {
            alert(array[i]);
            $("input[name='" + array[i] + "']").prop('checked',true);
        }
    });

</script>
Previous
Next Post »