Very confusing title. I just want to create a button that indicates the status of an order. If it's pressed, then the order is complete. If it's unpressed, the it's still pending.
Do you know of any plugins for this sort of functionality?
EDITS
Here is the route I have decided to take.
<div id="statuses"> <a id="first" class="status">Waiting</a>
<a id="second" class="status">Waiting</a>
</div>
<input type="button" id="reset" value="Reset" />
Here's the JavaScript for the buttons:
var COOKIE_NAME = "selection";
function getObjectProperties(obj) {
var keys = [];
for (var k in obj) keys.push(k);
return keys;
}
function deserialize() {
$.cookie.json = true;
//read object from cookies
var selection = $.cookie(COOKIE_NAME);
console.log(selection);
if (selection !== undefined) {
//go over each property (first, second, ...)
$.each(getObjectProperties(selection), function (index, element) {
//find button by id
var $elem = $("#" + element);
//read selection value for button
var isSelected = selection[element];
if (isSelected) {
//mark button as selected
$elem.addClass("selected").html("Ready");
}
});
}
}
function serialize() {
//initialize empty object
var selection = {};
//go over each button
$(".status").each(function (index) {
var $this = $(this);
//add new property to object and assigning value to it ({first:false, second:true /*,....*/})
selection[$this.attr("id")] = $this.hasClass("selected");
});
console.log(selection);
//save object to cookie
$.cookie(COOKIE_NAME, selection);
}
$(document).on("click", ".status", function (e) {
var $this = $(this);
$this.toggleClass("selected");
var isSelected = $this.hasClass("selected");
$this.html(isSelected ? "Ready" : "Waiting");
serialize();
});
$(document).on("click", "#reset", function (e) {
$(".status").removeClass("selected").html("Waiting");
serialize();
});
deserialize();
I've also declared these in the head:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
With this, the buttons work as planned, but they fail to stay that way after page refresh.