Random buddy
Random buddy

Reputation: 19

input box disable stay

I have a checkbox and when I click that checkbox it disables but when I refresh the page it does back to not being disabled how do I make it stay disabled

$( "input[type='checkbox']").click(function(event){
  $(this).attr('disabled', true);

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type='checkbox' name='checkbox' id='checkBox' class='checkBox' />

Upvotes: 1

Views: 73

Answers (2)

Akhil Singh
Akhil Singh

Reputation: 730

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#checkBox1').click(function (event) {
                $(this).attr('disabled', true);
                localStorage.setItem('check', 1);

            });
            var chk = localStorage.getItem('check');
            if (chk) {
                $('#checkBox1').attr('disabled', true);
                $('#checkBox1').attr('checked', true);
            }
        });</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
       <input type='checkbox' name='checkbox' id='checkBox1' class='checkBox' />

    </div>
    </form>
</body>
</html>

Upvotes: 1

Sakkeer A
Sakkeer A

Reputation: 1100

Set the flag for the Checkbox, when you click it change the flag status into 'true', Then store it into your Local storage. Now, the checkbox value will display if you refresh the page. I don't know Javascript syntax. I,m Angular 2+ Typescript.

Upvotes: 2

Related Questions