Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button disable after clicking issue

I have a submit button in my login page. I want to disable the submit button after clicking once.I'ts working fine with this.disabled = true; query and after disable the button it's going to the next page. The problem is that when I press back button it's still is disable because the page is not reloaded from server,It's loading from the local cache. I want to enable the button every time when I come back to the login page. I can clear the cache but there is some problem like if it will load from the server and project will be slow. What will be the best way to do this?

<script>
$(document).ready(function(){
    $(document).on('click','button',function(){
        this.disabled = true
        window.location="https://www.google.co.in/"
    })
})
</script>
<body>
<button type="submit" id="button">Click Me!</button> 
</body>
like image 756
Nullify Avatar asked Oct 04 '22 10:10

Nullify


1 Answers

I set the buttons initial disabled attribute to disabled in the body html to prove that the code does enable it again (so you can remove that in the body) I hope this helps:

<script>
$(document).ready(function () {
$("#button").removeAttr('disabled');
$("#button").click(function(){
        $(this).attr('disabled','disabled');
        window.location="https://www.google.co.in/"
    });
});
</script>
<body>
<button type="submit" id="button" disabled="disabled">Click Me!</button> 
</body>
like image 168
SteveKB Avatar answered Oct 09 '22 20:10

SteveKB