Skip to content
Advertisement

Disable multiple buttons even after refresh in javascript and thymeleaf

The problem

I have multiple buttons that are connected to db to keep count of the clicks. They are in a column and each time you click on one, the value associated with that button increments by one.

enter image description here

The database table looks like this:

JavaScript

What I want is: when you click on any button it should disable all the buttons but still increment the one that has been clicked while also saving the cookies session so even after refreshing the page you can not click any buttons. So all button should disappear/disabled after one click.

What I have tried?

I have tried so many things such as this, but non works. The buttons still work and the increment still happen.

Here is my html page for that shown the pic above

JavaScript

And here is my controller get fetched when clicking on Vote Here

JavaScript

Advertisement

Answer

You should be able to do this entirely with server side cookies. For example, this worked for me

Controller:

JavaScript

Button:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement