in reply to CGI: Saving javascript variables

Another way: Use AJAX to update the variable on the server whenever it's toggled.

The downside is that you generate more traffic, and if you don't properly code it you may slow down the user experience

The advantage is that the state will be updated on the server even if the user never submits the form, for example if they just close the browser intending to come back later. You also don't have to send the state along with every single link or form on the page.