On Sun, 27 Nov 2016 22:33:33 -0800 (PST) Chris S <chris.sanic...@gmail.com> wrote:
[...] > I currently have my html file set up with a button and this toggle > switch. I also configured my webserver in go to be listening on > localhost:8080. And I have a websocket handler configured, so that I > can easily pass data through to my webpage on the click of the button. > > What I want to do create a toggle switch on my webpage that the user > can switch on and off, and then have them click a button. After that > button is clicked I want to analyse the users selection using an if > condition in my golang code based on whether this toggle switch is > on/off, but I cannot figure out how to access this value in go. Any > suggestions would be helpful. Also, it'd be ideal to have a toggle > switch implemented, but if anyone has any simpler ideas for this use > case then I'd be open to them. You're (probably) supposed to use some JavaScript on your page so that when the user activates your toggle, you perform a request through that web socket. A handler installed to listen on that websocket in your Go server should parse the request sent from the browser and act accordingly. The best course of action is to break this task into subtasks and have them solved one-by-one: * Make sure activating your toggle calls whatever JS code you intend. For this, use plain console.log("whatever") and see whether it works in your browser's developer window. Note that contemporary browsers even allow you to execute your JS handlers step-by-step and set breakpoints. * Make sure your JS handler performs the request through the web socket. Again, this can be checked in the browser's developer window. It allows you to inspect the request's properties. * Make sure your Go handler works. Match that what you install on the Go side with what you've inspected using the browser's developer tools. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.