How do I make sure that the position of the toggle is saved?

I have a toggle, and I need a person to drag it offline when they leave and save this choice to the page. Can you tell me how to implement this?

image