Thanks for the response Konstantin,

I do have my go handler configured, as well as my ws function in javascript
configured to be triggered on the click of a button. Forgot to mention
this. right now on the click of a button I can execute a terminal command
in go, and output the results in realtime on my webpage. But what I want to
do is configure a toggle switch on my webpage so that if the switch is in
an on position, then when I click the button, I can execute a terminal
command in my go code, and if the switch is off, after I click the button
my go code will execute a different terminal command. Here is the toggle
switch I have implemented: http://www.bootstraptoggle.com/

But now I'm stuck on how to read whether this switch is in its off/on
position in my go code. Any suggestions would help.

On Mon, Nov 28, 2016 at 3:28 AM, Konstantin Khomoutov <
flatw...@users.sourceforge.net> wrote:

> 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.

Reply via email to