Add text to calendar

Hello everyone. I want to add each array element to each day. but it only adds 7 element. How can I do it?

CSS:

.ui-datepicker td[title]::after {
  content: attr(title);
  display: block;
  position: relative;
  font-size: .8em;
  height: 1.25em;
  margin-top: -1.25em;
  text-align: right;
  padding-right: .25em;
}

JavaScript

$(function() {
  var dayrates = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31];

  $("#datepicker").datepicker({
    beforeShowDay: function(date) {
      var selectable = true;
      var classname = "";
      var title = "\u20AC" + dayrates[date.getDay()];
      return [selectable, classname, title];
    }
  });
});

Currently you use date.getDay() which gives a day of the week from 0 for Sun to 6 for Sat.

Do you want to use the day of the month instead from 0 to 31? In that case, use date.getDate()
If you want to use it to refer to an array index, subtract 1 from it to start at index 0.

dayrates[date.getDate() - 1]

1 Like

Yes, I want 0 to 31

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.