Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In html, how do I generate table column name as current month's name? For example.

For this month table header should like :

StudentName March

Next month,
StudentName April
and so on..

What I have tried:



Student Name Current Month
Rabiya 123
Posted
Updated 20-Mar-16 23:17pm
Comments
CHill60 21-Mar-16 4:56am    
What have you tried?
Andy Lanng 21-Mar-16 5:00am    
Also, What kind of table are you using? How do you populate that table? Are you using any server side language or is this pure html?
Showing us your code would be a good start.
Supraja05 21-Mar-16 5:17am    
Hello.. I'm working with Ruby n rails.. In the view part,I want to fetch the name of all students and their current month's work progress.

AS of now,

<table>
<tr>
<th>Student</th>
<th id="month"></th>
</tr>
</table>

//javascript

var month = ['jan','feb','mar','apr',....]
var d= new Date();
$("#month").html(month[d.getMonth()])

//i.e html id month should be replaced with current month's name..

Am I clear now?

1 solution

Try with below code:
HTML
<html>
<body>
<table border="1" cellpadding="0" cellspacing="0">
	<tr>
		<th>
		StudentName
		</th>
		<th id="monthName">
		</th>
	</tr>
	<tr>
		<td>
		Manas
		</td>
		<td>
		1000
		</td>
	</tr>
</table>

<script>
    var month = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];

    var d = new Date();
    var n = month[d.getMonth()];
    document.getElementById("monthName").innerHTML = n;
</script>
</body>
</html>
 
Share this answer
 
v3
Comments
Supraja05 21-Mar-16 5:36am    
Thanks Manas. It works fine! What was wrong with my code?
P.S I'm new to html.
[no name] 21-Mar-16 5:42am    
If it helps please accept the answer.

As per your code it should work. Did you add jQuery reference in your page?

Supraja05 21-Mar-16 6:13am    
But doesn't work when

<table id ="reports" class ="table "data-toggle="table" data-show-columns="true" data-search="true" data-pagination="true" data-show-filter="true">
....
</table>

That field (col name) is empty when I add the above
[no name] 21-Mar-16 6:18am    
What is not working - month name not displaying?
[no name] 21-Mar-16 6:26am    
Where is <th> in above code.

Do you have same id(<th id="month">) name multiple times in your page?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900