Preety Angel Preety Angel - 7 months ago 6
Javascript Question

How to call the function for date and display in the slot with next 6days

Hi I have this DEMO
I want to display the date slot with current date and next 6 days. I have this HTML CODE:

<div class="date_slide">
<div id="date-slider" class="dragdealer">
<ul class="list_date">
<li id="date1">
SAT<br>2</br>APR
</li>
<li id="date2">
SUN<br>3</br>APR
</li>
<li id="date3">
MON<br>4</br>APR
</li>
<li id="date4">
TUS<br>5</br>APR
</li>
<li id="date5">
WED<br>6</br>APR
</li>
<li id="date6">
THU<br>7</br>APR
</li>
<li id="date7">
FRI<br>8</br>APR
</li>
</ul>
<div class="handle red-bar">
<span class="value"></span>
</div>
</div>
</div>


JS:

var current_date = new Date();
var next_date = new Date();
var i,j;

var date = current_date.getDate();

var tot_days = new Array(7);
var dd, mm;
for(j=0; j<7; j++){
dd = next_date.getDay();

mm = next_date.getMonth();
if(mm==0){
mm="JAN";
}else if(mm==1){
mm="FEB";
}else if(mm==2){
mm="MAR";
} else if(mm==3){
mm="APR";
} else if(mm==4){
mm="MAY";
} else if(mm==5){
mm="JUN";
} else if(mm==6){
mm="JUL";
} else if(mm==7){
mm="AUG";
} else if(mm==8){
mm="SEP";
} else if(mm==9){
mm="OCT";
} else if(mm==10){
mm="NOV";
} else if(mm==11){
mm="DEC";
}

if(dd==0){
dd="SUN";
}else if(dd==1){
dd="MON";
}else if(dd==2){
dd="TUE";
}else if(dd==3){
dd="WED";
}else if(dd==4){
dd="THU";
}else if(dd==5){
dd="FRI";
}else if(dd==6){
dd="SAT";
}

tot_days[j] = next_date.getDate() + "<br>" + dd + "<br>" + mm;
next_date.setDate(next_date.getDate() + 1);
document.write(tot_days[j]);


This JS show the day, date and month fine as I wanted. But I am confused how shall I apply this JS in the code so that the dates which are hard coded now shows the correct dates following with next 6 days. Any suggestions please. Its not necessary that it should be javascript, jquery will also work for me. I just need this thing to work properly.

Answer

Instead of document.write(tot_days[j]):

document.getElementById("date" + (j + 1)).innerHTML = tot_days[j];
Comments