Q:

How to build a simple web toggle?

I need to build a very simple button on a website that toggles a boolean on the server. When the boolean is True, I want to show a green icon, when it's False, I want to make it red. When a user clicks the icon, it should send a command to the server and update, then the icon should only change colors (image src) when the server has replied that the boolean has in fact been toggled.
I'm not very experienced with web apps, but I'm wondering what framework would work best for this? Is there an easy-to-use HTML5 way to do this? AJAX? Websocket? I'm using websockets on another page of the app and it's working, but it might be overkill for something this simple?

A:

Websockets are complete overkill for this, however you said you have another part of the application done...what is your backend?  If you like C#, ASP.NET has a lot of choices for you (MVC4 is my personal favorite).
In MVC you would create an action inside your pages controller to interpret some JSON passed from an AJAX call kind of like this:
public JsonResult FooData(int _id)
{
    var dataContext = true;
    if(_id == 7)
      dataContext = false;

     return Json(dataContext, JsonRequestBehavior.AllowGet);
}

...and on your client side you would call the FooData method like this:
$.ajax({
        url: "MyController/FooData",
        data: { _id: obj.id },
        dataType: 'json',
        async: true,
        success: ChangeImage
    });

Where ChangeImage is a javascript function set as your ajax calls' success callback function, so it might look like this:
function ChangeImage(data) {
    if(data == true)
        document.getElementById('myImg').src = "red.jpg";
    else
        document.getElementById('myImg').src = "green.jpg";
}

It's short, sweet and to the point.  There's a learning curve but it's well worth the time and effort.  I can't live without this framework anymore!
EDIT:  Forgot to add data to pass in the ajax call, fixed now!
EDIT EDIT:  I didn't add the logic of if click check bool -> if true, set false -> send flag -> if flag == 'change' change color -> if click ... etc etc etc because that's just busy work.  This is more than enough to get you there though.

