Hello, I would like to know if it is possible to access value of a cookie store through in javascript.
i have a value saved in java cookie, i would like to access this value in my javascript. It's possible?
@flaviamantunes You can access it through its name, javalin-cookie-store, but you have to decode the value yourself (it's base64 encoded)
The cookie-store is specifically meant to be used for the server-side though, could you describe your use case?
@tipsy So, I have a form in html, via javalin I'm taking his data, and saving cookies to keep them accessible without loss. When I make a query, I'm filling in the form inputs (via java) with javalin. But 'radiobutton' can only be completed via javascript. So I would like to access the cookie value 'radiobutton' via javascript in order to set 'checked'.
I am currently using new javascript cookies, but would like to use the existing ones in 'cookiestore'.
Flavia,
Do you actually need cookies? As I understand - you want to preserve user selections in the form (or do you want them to be in cookies and even read those values in backend? Usually it's backend that stores and reads cookies between user requests).
There is such thing as local storage (popular option) and session storage, both will let javascript save and get values in user browser (not between different browsers).
Here's good intro I found: https://medium.com/better-programming/how-to-use-local-storage-with-javascript-9598834c8b72
Anyway, here's pretty good info about cookies and how to use them, since you need to learn them: https://flaviocopes.com/cookies/
Let me know what you think about it.
@ernestas2k I had tried using localStorage before, and it had not worked properly. Through the link you sent I was able to run with it, and removed the cookies! Thank you so much!
@flaviamantunes great news!
Most helpful comment
@flaviamantunes great news!