trewyn15
New Member
Hey guys, I'm having more trouble in the class that I had the Javascript issue in..
This calendar is supposed to show the date that is entered and bold that specific day.
Here is the assignment:
Here is my current code:
I have most of it down, but I'm not sure how exactly to make the day that is typed in, bold.
Any help or hints would be greatly appreciated!
This calendar is supposed to show the date that is entered and bold that specific day.
Here is the assignment:
Here is my current code:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Calendar - Trewyn</title>
</head>
<body>
<script type="text/javascript">
daysOfWeek = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
monthsOfYear = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September','October', 'November', 'December'];
currentDate = new Date();
function Calendar(month, year)
{
this.month = (isNaN(month) || month == null) ? currentDate .getMonth() : month;
this.year = (isNaN(year) || year == null) ? currentDate .getFullYear() : year;
this.html = '';
}
Calendar.prototype.generateHTML = function()
{
var firstDayOfMonth = new Date(this.year, this.month, 1);
var startingDayOfMonth = firstDayOfMonth.getDay();
var numberOfDaysInMonth = daysInMonth [this.month];
if (this.month == 1) { // only for february
if((this.year % 4 == 0 && this.year % 100 != 0) || this.year % 400 == 0)
{
numberOfDaysInMonth = 29
}
}
var nameOfMonth = monthsOfYear [this.month]
var html = '<table class="calendar-table">';
html += '<tr><th colspan="7">';
html += nameOfMonth + " " + this.year;
html += '</th></tr>';
html += '<tr class="calendar-header">';
for(var i = 0; i <= 6; i++ )
{
html += '<td class="calendar-header-day">';
html += daysOfWeek [i];
html += '</td>';
}
html += '</tr><tr>';
var day = 1;
for (var i = 0; i < 9; i++)
{
for (var j = 0; j <= 6; j++)
{
html += '<td class="calendar-day">';
if (day <= numberOfDaysInMonth && (i > 0 || j >= startingDayOfMonth))
{
html += day;
day++;
}
html += '</td>';
}
if (day > numberOfDaysInMonth) {
break;
}
else {
html += '</tr><tr>';
}
}
html += '</tr></table>';
this.html = html;
}
Calendar.prototype.getHTML = function() {
return this.html;
}
function printCalendar(month, year, day)
{
var cal = new Calendar(month, year);
cal.generateHTML();
document.write(cal.getHTML());
}
function getInput()
{
var currentYear = document.getElementById("year").value;
var currentMonth = document.getElementById("month").value;
var currentDay = document.getElementById("day").value;
printCalendar(currentMonth, currentYear);
}
</script>
<form>
Day: <input type="text" id="day" name="day"/> (1-31)<br/>
Month: <input type="text" id="month" name="month"/> (1-12)<br/>
Year: <input type="text" id="year" name="year"/> (4-Digits) <br/>
<input type="button" value="Submit" onclick="getInput()" /> <br/>
</form>
<br/> All values must be given
within the limits of the numbers specified to the right of each text box, or the input will be 'undefined'.
</body>
</html>
I have most of it down, but I'm not sure how exactly to make the day that is typed in, bold.
Any help or hints would be greatly appreciated!