jquery - How to Permanently Disable a button using Javascript in asp.net? -
i've created countdown timer using javascript in asp.net. after completion of time, button1
becomes disabled, when reload page, countdown timer reset , button1
enabled.
i want permanently disable button1
when timer equal zero. code is:
var tim; var min = 01; var sec = 00; var f = new date(); function f1() { f2(); } function f2() { if (parseint(sec) > 0) { sec = parseint(sec) - 1; document.getelementbyid("showtime").innerhtml = ""+min+" minutes ,"+sec+" seconds"; tim = settimeout("f2()", 1000); } else { if (parseint(sec) == 0) { min = parseint(min) - 1; if (parseint(min) == -1) { cleartimeout(tim); $("#button1").prop('disabled', true); } else { sec = 60; document.getelementbyid("showtime").innerhtml = "" + min + " minutes ," + sec + " seconds"; tim = settimeout("f2()", 1000); } } } }
<body onload="f1()"> <div><h3>time finished after:</h3> </div> <div id="showtime"></div> <div> <asp:button id="button1" runat="server" text="submit"/></div>` </body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script> <script> function f2() { if (parseint(sec) > 0) { sec = parseint(sec) - 1; document.getelementbyid("showtime").innerhtml = ""+min+" minutes ,"+sec+" seconds"; tim = settimeout("f2()", 1000); } else { if (parseint(sec) == 0) { min = parseint(min) - 1; if (parseint(min) == -1) { cleartimeout(tim); $("#button1").prop('disabled', 'true'); storevalue('disabled', 'true'); } else { sec = 60; document.getelementbyid("showtime").innerhtml = "" + min + " minutes ," + sec + " seconds"; tim = settimeout("f2()", 1000); } } } } function storevalue(key, value) { if (localstorage) { localstorage.setitem(key, value); } else { $.cookies.set(key, value); } } function getstoredvalue(key) { if (localstorage) { return localstorage.getitem(key); } else { return $.cookies.get(key); } } function f1() { f2(); var model =getstoredvalue('disabled'); if(model == 'true') { $("#button1").prop('disabled', 'true'); } } var tim; var min = 01; var sec = 00; var f = new date(); </script>
use code , make thrid party localstorage use in browser
Comments
Post a Comment