I had a requirement to fill the select list with calender dates in format DD-MM-YYYY which i did with the following script. It populates select list with date of next 90days .
Now client request has changed and he wants to fill the select list with dates only if it is Saturday, Monday or Wednesday.. I am not able to resolve this on i tried to modify the script but it didnot work.
Below script is working. Any help in this area is appreciated
<script>
$(function(){
function pad(n){return n<10 ? '0'+n : n}
var date = new Date();
var selectElement = $('<select name="dddDate" class="ddDate" >'), optionElement;
for (var count =0; count < 90; count++){
formattedDate = pad(date.getUTCDate()) + '-' + pad(date.getUTCMonth()+1) + '-' + date.getUTCFullYear();
optionElement = $('<option>')
optionElement.attr('value',formattedDate);
optionElement.text(formattedDate);
selectElement.append(optionElement);
date.setDate(date.getDate() +1);
}
$('#ddDate').append(selectElement);
});
</script>
<body>
<div id="ddDate"> </div>
</body>
Date.getDay( ): return the day-of-the-week field of a Date. Return values are between 0 (Sunday) and 6 (Saturday).
http://jsfiddle.net/UvDEa/