I have the following json output:
[{"shift":"1","start":"08:00","end":"20:00"},
{"shift":"2","start":"09:00","end":"21:00"},
{"shift":"3","start":"10:00","end":"22:00"},
{"shift":"4","start":"11:00","end":"23:00"},
{"shift":"5","start":"12:00","end":"00:00"},
{"shift":"6","start":"13:00","end":"01:00"},
{"shift":"7","start":"14:00","end":"02:00"} .... ]
And looking to print the shift number when current time fall between tow times, i.e: if current time is 10:30, then I will get:
shift 1 shift 2 shift 3
$.getJSON( "http://server/api/shifts", function( data ) {
$.each(data, function(index, item) {
var shiftStart = item.start,
shiftEnd = item.end,
now = moment().format("HH:mm") ;
if (now > shiftStart && now < shiftEnd) {
var x = document.getElementById("shift_id");
var option = document.createElement("option");
option.text = item.shift;
x.add(option);
}
});
});
I get nothing in the select box