0

Am unsatified with the other answers with realted question asked by me. i want each column header of a html to be displayed with a individual date when web page is loaded to that specific month in javascript. I tried but i got no success. Here is my javascript code.

function addRows(table, dates) {
        var idx = 1;
        for (var i in dates) {
            table.append(
                         '<th><input name="date'+idx+'" id="date'+idx+'" class="date" value="'+dates[i]+'"></th>'
             );
            idx++;
        }
    }

    $(function() {
        var myDate = new Date();
        var year   = myDate.getFullYear();
        var month  = myDate.getMonth(); 
        var dates  = myDate.daysInMonth(year, month);
        var table  = $("#myTable").find("tbody");
        addRows(table, dates);
    });`
Rajesh Pandya
  • 1,540
  • 4
  • 18
  • 31
Naim
  • 19
  • 7

1 Answers1

0

link below will show you the code to create an array wit each date in it.

Find all the days in a month with Date object?

you could then map over the array creating a table header for each item in the array

Steve Bohmbach
  • 327
  • 1
  • 11
  • Thanks for the link Mr. Steve Bohmbach. The problem is am able to get the dates according to the specific month and am able to display vertically but i want to set each individual day date Horizontally in a table like excel dates, to individual column header i.e' in of a table header. Can you Help me Out please ? – Naim Jun 12 '18 at 05:25
  • @Naim are you encasing the items in a tag? – Steve Bohmbach Jun 12 '18 at 15:47
  • Yes Mr steve, and am encasing within . – Naim Jun 13 '18 at 06:47
  • How do i append those dates in each individual on top of the table ?? i hope my problem will be solved. – Naim Jun 13 '18 at 07:34