i want user open webpage and textbox show value of current friday. i don't know how to use .val here is my code.
$(function() {
$("#dateInput").datepicker({
//In Datepicker set the Calendar display start with Sunday (by default datepicker starts from Sunday)
firstDay: 0,
//Before Populating the Calendar set the Enabled & Disabled Dates using beforeShowDay(Date) function
beforeShowDay: function (date) {
//Get today's date
var sunday = new Date();
//Set the time of today's date to 00:00:00
sunday.setHours(0,0,0,0);
sunday.setDate(sunday.getDate() - (sunday.getDay() || 0));
//Set the Date to Sunday
var saturday = new Date(sunday);
var thrusday = new Date(sunday);
var currentday = new Date();
//0 is sunday 6 is saturday
var currentdayofweek = currentday.getUTCDay();
//console.log(currentday, "show currentday");
//alert('value of currentday=>'+currentday);
//alert('value of currentday of week=>'+currentdayofweek);
//location.reload();
//Now add 6 to Sunday to get the Date of Saturday (End of that Week)
saturday.setDate(sunday.getDate() + 6);
//add by kim
thrusday.setDate(sunday.getDate() + 4);
//edit by kim
//return [(date >= thrusday && date <= saturday ), ''];
// current day of week <5 mean user can select friday only day before friday
return [(date > thrusday && date < saturday && currentdayofweek < 5), ''];
}
});
var temp = $("#dateInput").datepicker("option", "dateFormat", "yy-mm-dd");
return temp;
});
and here is textbox code.
<input type="text" name="dateInput" id="dateInput"/>
This will fill the #dateInput
input with the date corresponding to the Friday of the current week.
var date = new Date(),
day = date.getDay(),
dif = 5 - day >= 0 ? 5 - day : day - 5;
date.setTime( date.getTime() + (dif * 24 * 60 * 60 * 1000) );
$(document).ready(function() {
$("#dateInput").val( date.getUTCFullYear() + "/" + (date.getMonth()+1) + "/" + date.getUTCDate() );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="text" name="dateInput" id="dateInput"/>
</div>
marventus . i mean Format is correct but the date is not current friday that show in textbox. example . user login to system at saturday 2015/1/3 , system should input next friday for user. it should be 2015/1/9 . But your code input value into textbox is 2015/1/4