Javascript Form How to - Set and get the indeterminate state of a CheckBox








Question

We would like to know how to set and get the indeterminate state of a CheckBox.

Answer


    <!--from www.ja v  a2s .co m-->
<html>
<body>
    <input type="checkbox" id="myCheckBox" value="checkbox" checked>
    Indeterminate = true.
    <input type="button" value="Checkbox state" onClick="function1();">
    <script language="JavaScript">
    document.all.myCheckBox.indeterminate = true;
    function function1() {
       var m = document.all.myCheckBox.indeterminate;
       console.log("Indeterminate: "+m); 
    } 
    </script>
</body>
</html>

The code above is rendered as follows: