Highlight hours of entire week for selected date

<script language=”javascript”>
///datetime code
var selected_date = “4/13/2015”;
var myDate = new Date(selected_date);
var seldate = myDate;
var seldate_new = myDate;
var dayno = parseInt( myDate.getDay() );
var objString = “”;
objString += “<table cellpadding=3><tr><td colspan=’7′ style=’background-color: lightgray;’>Selected Date=”+selected_date+”</td></tr>”;
//slots of week
var jsonslots = ‘[‘ +
‘{ “slot_hour”:”4″ , “slot_day”:”15″, “slot_month”:”4″, “slot_year”:”2015″ },’ +
‘{ “slot_hour”:”3″ , “slot_day”:”15″, “slot_month”:”4″, “slot_year”:”2015″ },’ +
‘{ “slot_hour”:”14″ , “slot_day”:”16″, “slot_month”:”4″, “slot_year”:”2015″ }’ +
‘]’;
var objJson = JSON.parse(jsonslots);
//end slots of week

objString += “<tr><td colspan=’7′ style=’background-color: lightgray;’>Slots={15/4/2015 [4-5],[3-4]},{16/4/2015 [14-15]} </td></tr>”;
objString += “<tr>”;
for( i =0; i<7; i++){
objString += (“<td>”);
seldate_new = new Date(selected_date);
if( i< dayno ){
seldate = new Date(seldate_new.setDate( myDate.getDate() – (dayno-i) ));
objString += seldate;
}else if( i == dayno ){
seldate = new Date(seldate_new.setDate( myDate.getDate() ));
objString += seldate;
}else{
seldate = new Date(seldate_new.setDate( myDate.getDate() + (i-dayno) ));
objString += seldate;
}
var current_month = seldate.getMonth(); //months from 1-12
var current_day = seldate.getDate();
var current_year = seldate.getFullYear();

objString += “<table border=1 width=’100%’>”;
//for hour slots
for( K =0; K<24; K++){
available_hour = 0;
available_day = 0;
available_month = 0;
available_year = 0;
matched_slot = false;
//write here for check date, slot, and then print radio
for (var key in objJson) {
if (objJson.hasOwnProperty(key)) {
available_hour = (objJson[key].slot_hour);
available_day = (objJson[key].slot_day);
available_month = (objJson[key].slot_month);
available_year = (objJson[key].slot_year);
if( parseInt(available_year ) == parseInt(current_year) && parseInt(available_month) == (parseInt( current_month)+1) && parseInt(available_day) == parseInt(current_day) && parseInt(available_hour) == parseInt(K) ){
matched_slot = true;
}
}
}
//end slot value

if(matched_slot == false ){
objString += “<tr><td>”;
objString += K+”-“+(parseInt(K)+1);
objString += “<INPUT type=’radio’ name=’rdo_”+( “_” + (parseInt( current_month)+1) + “_” + current_day + “_” + current_year)+”‘ id=’rdo_”+( “_” + (parseInt( current_month)+1) + “_” + current_day + “_” + current_year + “_” + K)+”‘ value='”+K+”‘>”;
objString += “</td></tr>”;
}else{
objString += “<tr><td style=’background-color: red;’>”;
objString += K+”-“+(parseInt(K)+1);
objString += “<INPUT type=’radio’ name=’rdo_”+( “_” + (parseInt( current_month)+1) + “_” + current_day + “_” + current_year)+”‘ id=’rdo_”+( “_” + (parseInt( current_month)+1) + “_” + current_day + “_” + current_year + “_” + K)+”‘ value='”+K+”‘ disabled>”;
objString += “</td></tr>”;
}

}
objString += “</table>”;
objString += “</td>”;
}
objString += “</tr></table>”;
document.write(objString);
</script>

Tags: ,