...

View Full Version : getFullYear() displays five digit year



KimberCat
04-30-2007, 09:13 PM
How do I change the following code so that it doesn't display the year as 20061 and 20062? A friend paid a so-called Javascript developer a lot of money for this calendar and it doesn't work right and he took off with her money. TIA, KimberCat



/*******************
* HEADER FUNCTIONS *
*******************/
message1 = "<p><em>We hope this calendar will help you decide on the perfect time to schedule your Nuchal Translucency session with Look of Love.</em></p>";
function welcome(){
message = message1 + "<h4><em>Please click on the day of your LMP (the FIRST day of your Last Menstrual Period).</em></h4><br><br>";
return message;
}

function thanks(){
message = message1 + "<h4><em>Please call us to schedule your appointment: 828-271-4700</em></h4><br><br>";
return message;
}

/*********
* ARRAYS *
*********/
var dayWeek = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
var monthYear = new Array('January','February','March','April','May','June','July','August','September','October','Novem ber','December');

/************
* VARIABLES *
************/
var oneDay = 86400000; //no of ms in a day
var start;

var Calendar = new Date();
var year = Calendar.getFullYear(); // returns current year in four digit format
var month = Calendar.getMonth(); // returns current monthYear (0-11)
var today = Calendar.getDate(); // returns current dayMonth (1-31)
var weekDay = Calendar.getDay(); // returns current dayWeek (1-7)

var weekLength = 7;
var monthLength = 31;
var cal;

var startDate=new Date();
startDate.setDate(startDate.getDate()-240); // go back in time 240 days

var LMPDate = Date();
LMPDate = startDate;

if(LMPDate==startDate){
//document.write('today: '+LMPDate);
thisYear=LMPDate.getFullYear();
thisMonth=LMPDate.getMonth();
//document.write('today: '+thisYear+'-'+thisMonth);
}
else{
//document.write('LMP: '+LMPDate);
thisYear=LMPDate.getFullYear();
thisMonth=LMPDate.getMonth();
//document.write('lmp: '+thisYear+'-'+thisMonth);
}

// This Function Generates the Calendar
// away = months away from this month
function DisplayCalendar(month,year)
{
var tempMonth = month;
if (tempMonth >11) {
tempMonth -=12;
if (tempMonth == 0) thisYear ++;
}

startDate.setDate(1); // Calendar start at day 1
startDate.setMonth(tempMonth); // Calendar start at month given

var startRow = '<tr>';
var endRow = '</tr>';
var startCell = '<td class="day">';
var endCell = '</td>';

/*******************************
* CALENDAR HTML CREATION START *
*******************************/
cal = '<br><br><table class="one-cal"><tr><td>';
cal += '<table class="one-month">' + startRow;
cal += '<td colspan="' + weekLength + '">';
//cal += '<div class="month">' + monthYear[tempMonth] + ' &nbsp;' + year + '</div>' + endCell + endRow;
cal += '<div class="month">' + monthYear[tempMonth] + ' &nbsp;' + year + '</div>' + endCell + endRow;
cal += startRow;

/***********************************************************************/

// EACH DAY OF WEEK
for(count=0; count < weekLength; count++)
{
cal += startCell + '<span>' + dayWeek[count] + '</span>' + endCell;
}

cal += endCell + endRow;
cal += startRow;

// BLANK SPACES
for(count=0; count < startDate.getDay(); count++)
cal += startCell + '&nbsp; ' + endCell;

// EACH DAY IN MONTH
for(count=0; count < monthLength; count++)
{
if( startDate.getDate() > count )
{
//NEXT DAY
weekDayNext =startDate.getDay();

// NEW ROW EVERY SUNDAY
if(weekDayNext == 0)
cal += startRow;

// SET VARIABLE INSIDE LOOP FOR INCREMENTING PURPOSES
if(weekDayNext != weekLength) {
var day = startDate.getDate();
//document.write("<!--"+ ( Date.parse(LMPDate)-Date.parse(startDate) )/oneDay +"-->");
cal += "<td onClick='start=false;SetLMPDate(&quot;" + startDate + "&quot;);' class='"+ dateClass(startDate, LMPDate) +"'>"+ day + "</td>";


}

// END ROW FOR LAST DAY OF WEEK
if(weekDayNext == weekLength)
cal += endRow;
}

// INCREMENTS UNTIL END OF THE MONTH
startDate.setDate(startDate.getDate()+1);

}// end for loop

cal += '</td></td></table></table>';

/*********************************
PRINT CALENDAR
********************************/

return cal;
//-->
}

function SetLMPDate(lmp){
LMPDate = lmp;

var thisDate = new Date(lmp);
thisYear = thisDate.getFullYear(); // returns current year
thisMonth = thisDate.getMonth(); // returns current monthYear (0-11)

document.getElementById("month1").innerHTML = DisplayCalendar(thisMonth,thisYear);
document.getElementById("month2").innerHTML = DisplayCalendar(thisMonth+1,thisYear);
document.getElementById("month3").innerHTML = DisplayCalendar(thisMonth+2,thisYear);
document.getElementById("month4").innerHTML = DisplayCalendar(thisMonth+3,thisYear);
document.getElementById("month5").innerHTML = DisplayCalendar(thisMonth+4,thisYear);
document.getElementById("month6").innerHTML = DisplayCalendar(thisMonth+5,thisYear);
document.getElementById("month7").innerHTML = DisplayCalendar(thisMonth+6,thisYear);
document.getElementById("month8").innerHTML = DisplayCalendar(thisMonth+7,thisYear);
document.getElementById("month9").innerHTML = DisplayCalendar(thisMonth+8,thisYear);

if (start==false)
document.getElementById("header").innerHTML = thanks();
else {
document.getElementById("header").innerHTML = welcome();

}

}


function dateClass(startDate, LMPDate) {

var classname = 'day';
var tempNum;
var holdDate1 = Date.parse( LMPDate );
var holdDate2 = Date.parse( startDate );
// document.write('1: '+holdDate1+' 2: '+holdDate2);
var number = holdDate1-holdDate2 ;

// Get difference in days
tempNum = number / oneDay ;
if (start==false) {
if (tempNum == 0 ){
classname = 'lmp'; // due date
}
if ( (tempNum >= -71 & tempNum < -61) || (tempNum >= -76 & tempNum < -72) ) {
classname = 'day-bloodtest'; // days for blood tests
} //end IF
else{
if ( (tempNum >= -72 & tempNum < -71) ) {
classname = 'day-bloodtest-ideal'; // ideal day for blood tests
} //end IF
else {
if (tempNum > -96 & tempNum < -76) {
classname = 'day-both'; // week to see body
} //end IF

} //end ELSE
} //end ELSE
}
return classname;
} //end FUNCTION

nikkiH
04-30-2007, 09:57 PM
var LMPDate = Date();
LMPDate = startDate;

if(LMPDate==startDate){


Wow.
She got gypped.
Anyway, copying that code into a new doc doesn't do anything. Got a link, or a test doc? Something likely calls the function, or there's a start point in the body onload somewhere.

nikkiH
04-30-2007, 09:59 PM
Actually, looking closer, there's a lot of document.getElementById in there, so I do need a full test document with all those divs in there.

KimberCat
04-30-2007, 10:09 PM
Sorry, here's the html page and the two css files.

HTML


<!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>Look of Love - Asheville, NC - 3D Prenatal Ultrasound Nuchal Translucency Calendar</title>
<link href="../baby.css" type="text/css" rel="stylesheet">
<link href="calendar-nt.css" type="text/css" rel="stylesheet">
<script src="calendar-nt.js" type="text/javascript"></script>
</head>


<body onload="SetLMPDate(startDate+1); start=true">

<div id="header">
</div>



<div id="month1"></div>
<div id="month2"></div>
<div id="month3"></div>
<div id="month4"></div>
<div id="month5"></div>
<div id="month6"></div>
<div id="month7"></div>
<div id="month8"></div>
<div id="month9"></div>


<div id="legends">

<div id="legend1">
<span class="square day-bloodtest"><img style="" src="../img/spacer.gif" border="0" height="10" width="15"></span>
<span class="week-legend"> Blood test can be taken</span>
</div>

<div id="legend2">
<span class="square day-bloodtest-ideal"><img style="" src="../img/spacer.gif" border="0" height="10" width="15"></span>
<span class="week-legend"> Ideal day for taking blood test</span>

</div>

<div id="legend3">
<span class="square day-both"><img style="" src="../img/spacer.gif" border="0" height="10" width="15"></span>
<span class="week-legend"> Both the blood test and the ultrascan can be taken</span>
</div>

<div id="legend6">
<span class="square lmp"><img style="" src="../img/spacer.gif" border="0" height="10" width="15"></span>
<span class="week-legend"> The first day of your LMP</span>

</div>


</div>

</body>
</html>



baby.css


body, .layout
{
background-color: #f5eee8;
width: 1024px;
margin: 0;
padding: 0;
border-collapse: collapse;
display: block;
}

.topbar
{
background-color: #f5eee8;
width: 1024px;
margin: 0;
padding: 0;
border-collapse: collapse;
}

.leftbar
{
width: 168px;
padding: 35px 0 22px 0;
}

.topbar img
{
display: block;
margin: 0;
}

.vertical-menu
{
margin: 0;
padding: 0;
}

.vertical-menu li, .vertical-menu li img
{
list-style-type: none;
display: block;
margin: 0;
padding: 0;
border: 0;
}

.mainarea
{
padding: 10px 0 5px 5px;
margin: 0;
}

#content-news{
width: 840px;
padding: 0;
margin: 0;
color: #45124a;
vertical-align: top;
}
#content-content{
width: 820px;
padding: 0;
margin: 0;
color: #45124a;
vertical-align: top;
}

#content
{
color: #45124a;
padding: 5px 20px 10px 15px;
vertical-align: top;
}

#content-all { padding-right: 30px; }

#newsbar
{
width: 175px;
vertical-align: top;
background-image: url(http://lookofloveasheville.com/img/newsbar.jpg);
background-repeat: no-repeat;
}

#news
{
background-image: url(http://lookofloveasheville.com/img/news-body-.jpg);
background-repeat: repeat-y;
vertical-align: top;
color: #45124a;
margin: 10px 5px 6px 3px;
padding: 2px 20px 0 15px;
font-size: 10.5pt;
/*border: solid 1px black;*/
}
#newsbar-bottom
{
background-image: url(http://lookofloveasheville.com/img/news-body-.jpg);
background-repeat: repeat-y;
}

h2
{
font-family: Griffon, Times, Georgia, serif;
font-size: 17pt;
line-height: 21pt;
color: #45124a;
}

h3
{
font-family: Griffon, Times, Georgia, serif;
font-size: 14pt;
line-height: 18pt;
color: #45124a;
}

h4
{
font-family: Griffon, Times, Georgia, serif;
font-size: 13pt;
margin: 5px 0 5px 0;
padding: 0;
color: #45124a;
}

h5, .h5
{
font-family: Griffon, Times, Georgia, serif;
font-size: 12.5pt;
font-weight: normal;
margin: 5px 0 5px 0;
padding: 0;
font-style: normal;
}

h6, .h6
{
font-family: Griffon, Times, Georgia, serif;
font-size: 11pt;
font-weight: bold;
color: #45124a;
margin: 3px 0 3px 0;
padding: 0;
}

p, .p
{
font-family: Times, Georgia, serif;
font-size: 11pt;
line-height: 13pt;
margin: 5px 0 10px 0;
padding: 0;
text-decoration: none;
text-align: justify;
color: #45124a;
}

li
{
font-family: Times, Georgia, serif;
font-size: 11pt;
line-height: 12pt;
margin: 3px 0 4px 0;
padding: 0;
text-decoration: none;
}

ul { margin: 10px 5px 20px 15px; }

p a,
ul li a,
h3 a,
h4 a,
h5 a,
h6 a {
color: #45124a;
text-decoration: none;
}

p a:hover,
ul li a:hover,
h3 a:hover {
text-decoration: underline; }
.ita { font-style: italic; }
.centertext, centerimg { text-align: center; }
.righttext { text-align: right; }
.indent-1 { margin-left: 20px; }
.nobullet
{
list-style-type: none;
list-style-position: default;
}

.question { padding-top: 30px; }
.newsitems {
margin: 5px 1px 9px 3px;
padding: 0px 0 0 10px;
}
.newsitems li {
font-size: 9pt;
line-height: 10.5pt;
margin: 4px 0 7px 0;
padding: 0;
}
.btt
{
text-align: right;
font-size: 9pt;
}
.icon { margin: 2px 15px -1px 2px; }
.bottombar, .bottombar a
{
margin: 0;
font-family: Griffon, Times, Georgia, serif;
font-size: 16pt;
line-height: 21pt;
color: #45124a;
font-weight: bold;
text-align: center;
text-decoration: none;
}
.bottombar .lg { font-size: 20pt; font-style: italic; }
.separation {
border-bottom: 1px dotted #45124a;
}
.video {
display: block;
margin: 10px 20px 20px 55px;
background-color: #f5eee8;
}
.video-tip {
text-align: left;
padding: 10px 100px 10px 20px;
width: 180px;
vertical-align: top;
}
.video-tip p
{
font-weight: bold;
text-align: left;
font-style: italic;
font-size: 12pt;
margin-bottom: 15px;
}

.tip{
float:right;
text-align: left;
margin: 15px 100px 10px 0;
width: 180px;
}
.tip p
{
font-weight: bold;
text-align: left;
font-style: italic;
font-size: 12pt;
margin-bottom: 15px;
}
.logo-text
{
position: relative;
top: 1px;
}

.caption-box-right
{
width: 165px;
padding: 3px 0 0 10px;
float: right;
font-size: 9.5pt;
font-style: italic;
text-align: left;
margin: 0 0 5px 0;
}
.caption-box-right h6 {
font-size: 12pt;
}
.caption-box-left {
margin: 0 25px 10px 0;
float: left;

}
.caption {
font-size: 9pt;
font-style: italic;
text-align: left;
}
.photos {
border-collapse: separate;
margin-left: 10px;
}
.photos td {
padding: 0;
}
.photo-box {
background-color: #000000;
width: 200px;
height: 200px;
min-height: 200px;
}
img { border: 0; }
.photo { margin: 15px; }
.simple-table{
width: 630px;
vertical-align: top;
}
.simple-table td{

vertical-align: top;
}
.services {
width: 700px;
margin-left: 25px;
}
.services p {
font-size: 10pt;
}
.services li {
font-size: 10pt;
margin: 2px 0 3px 0;
}

.service-hd {
margin: 0 0 10px 0;
display: block;
}
.service-hd img {
text-align: center;

}
.fineprint {
font-size: 9pt;
}
.faq-content {
width: 790px;
}
.faq-content td { vertical-align: top;}
.quote {
font-size: 10pt;
font-style: italic;
text-align: left;
}
.border2 {
border: solid 1px #45124a;;
}

.align400
{
position: absolute;
left: 410px;
}




calendar-nt.css




body, .layout
{
background-color: #f5eee8;
width: 1024px;
margin: 0;
padding: 0;
border-collapse: collapse;
display: block;
}

.topbar
{
background-color: #f5eee8;
width: 1024px;
margin: 0;
padding: 0;
border-collapse: collapse;
}

.leftbar
{
width: 168px;
padding: 35px 0 22px 0;
}

.topbar img
{
display: block;
margin: 0;
}

.vertical-menu
{
margin: 0;
padding: 0;
}

.vertical-menu li, .vertical-menu li img
{
list-style-type: none;
display: block;
margin: 0;
padding: 0;
border: 0;
}

.mainarea
{
padding: 10px 0 5px 5px;
margin: 0;
}

#content-news{
width: 840px;
padding: 0;
margin: 0;
color: #45124a;
vertical-align: top;
}
#content-content{
width: 820px;
padding: 0;
margin: 0;
color: #45124a;
vertical-align: top;
}

#content
{
color: #45124a;
padding: 5px 20px 10px 15px;
vertical-align: top;
}

#content-all { padding-right: 30px; }

#newsbar
{
width: 175px;
vertical-align: top;
background-image: url(http://lookofloveasheville.com/img/newsbar.jpg);
background-repeat: no-repeat;
}

#news
{
background-image: url(http://lookofloveasheville.com/img/news-body-.jpg);
background-repeat: repeat-y;
vertical-align: top;
color: #45124a;
margin: 10px 5px 6px 3px;
padding: 2px 20px 0 15px;
font-size: 10.5pt;
/*border: solid 1px black;*/
}
#newsbar-bottom
{
background-image: url(http://lookofloveasheville.com/img/news-body-.jpg);
background-repeat: repeat-y;
}

h2
{
font-family: Griffon, Times, Georgia, serif;
font-size: 17pt;
line-height: 21pt;
color: #45124a;
}

h3
{
font-family: Griffon, Times, Georgia, serif;
font-size: 14pt;
line-height: 18pt;
color: #45124a;
}

h4
{
font-family: Griffon, Times, Georgia, serif;
font-size: 13pt;
margin: 5px 0 5px 0;
padding: 0;
color: #45124a;
}

h5, .h5
{
font-family: Griffon, Times, Georgia, serif;
font-size: 12.5pt;
font-weight: normal;
margin: 5px 0 5px 0;
padding: 0;
font-style: normal;
}

h6, .h6
{
font-family: Griffon, Times, Georgia, serif;
font-size: 11pt;
font-weight: bold;
color: #45124a;
margin: 3px 0 3px 0;
padding: 0;
}

p, .p
{
font-family: Times, Georgia, serif;
font-size: 11pt;
line-height: 13pt;
margin: 5px 0 10px 0;
padding: 0;
text-decoration: none;
text-align: justify;
color: #45124a;
}

li
{
font-family: Times, Georgia, serif;
font-size: 11pt;
line-height: 12pt;
margin: 3px 0 4px 0;
padding: 0;
text-decoration: none;
}

ul { margin: 10px 5px 20px 15px; }

p a,
ul li a,
h3 a,
h4 a,
h5 a,
h6 a {
color: #45124a;
text-decoration: none;
}

p a:hover,
ul li a:hover,
h3 a:hover {
text-decoration: underline; }
.ita { font-style: italic; }
.centertext, centerimg { text-align: center; }
.righttext { text-align: right; }
.indent-1 { margin-left: 20px; }
.nobullet
{
list-style-type: none;
list-style-position: default;
}

.question { padding-top: 30px; }
.newsitems {
margin: 5px 1px 9px 3px;
padding: 0px 0 0 10px;
}
.newsitems li {
font-size: 9pt;
line-height: 10.5pt;
margin: 4px 0 7px 0;
padding: 0;
}
.btt
{
text-align: right;
font-size: 9pt;
}
.icon { margin: 2px 15px -1px 2px; }
.bottombar, .bottombar a
{
margin: 0;
font-family: Griffon, Times, Georgia, serif;
font-size: 16pt;
line-height: 21pt;
color: #45124a;
font-weight: bold;
text-align: center;
text-decoration: none;
}
.bottombar .lg { font-size: 20pt; font-style: italic; }
.separation {
border-bottom: 1px dotted #45124a;
}
.video {
display: block;
margin: 10px 20px 20px 55px;
background-color: #f5eee8;
}
.video-tip {
text-align: left;
padding: 10px 100px 10px 20px;
width: 180px;
vertical-align: top;
}
.video-tip p
{
font-weight: bold;
text-align: left;
font-style: italic;
font-size: 12pt;
margin-bottom: 15px;
}

.tip{
float:right;
text-align: left;
margin: 15px 100px 10px 0;
width: 180px;
}
.tip p
{
font-weight: bold;
text-align: left;
font-style: italic;
font-size: 12pt;
margin-bottom: 15px;
}
.logo-text
{
position: relative;
top: 1px;
}

.caption-box-right
{
width: 165px;
padding: 3px 0 0 10px;
float: right;
font-size: 9.5pt;
font-style: italic;
text-align: left;
margin: 0 0 5px 0;
}
.caption-box-right h6 {
font-size: 12pt;
}
.caption-box-left {
margin: 0 25px 10px 0;
float: left;

}
.caption {
font-size: 9pt;
font-style: italic;
text-align: left;
}
.photos {
border-collapse: separate;
margin-left: 10px;
}
.photos td {
padding: 0;
}
.photo-box {
background-color: #000000;
width: 200px;
height: 200px;
min-height: 200px;
}
img { border: 0; }
.photo { margin: 15px; }
.simple-table{
width: 630px;
vertical-align: top;
}
.simple-table td{

vertical-align: top;
}
.services {
width: 700px;
margin-left: 25px;
}
.services p {
font-size: 10pt;
}
.services li {
font-size: 10pt;
margin: 2px 0 3px 0;
}

.service-hd {
margin: 0 0 10px 0;
display: block;
}
.service-hd img {
text-align: center;

}
.fineprint {
font-size: 9pt;
}
.faq-content {
width: 790px;
}
.faq-content td { vertical-align: top;}
.quote {
font-size: 10pt;
font-style: italic;
text-align: left;
}
.border2 {
border: solid 1px #45124a;;
}

.align400
{
position: absolute;
left: 410px;
}

nikkiH
05-01-2007, 05:39 PM
What was the intention here? This is what is screwing that up.

SetLMPDate(startDate+1)

change your onload to this to fix it.
<body onload="SetLMPDate(startDate); start=true">

If you meant the start date to be a day, a month, or a week ahead of the default, we can do that, but not like this. :)

KimberCat
05-08-2007, 01:25 AM
Sorry about the late reply, but I had to go out of town unexpectedly. My friend, who is an obstetrician wanted the code on her website to let her patients know when to schedule their NT scan.

First day of last period is DAY 1

NT scan can be done between 11 weeks and 13 weeks 6 days from Day 1
Finger stick blood test can be done from 9 weeks to 13 weeks 6 days

She wanted the colors to be clear about the fact that both tests can be done between 11 w and 13 w 6 d, but only the blood test can be done from 9weeks to 10 weeks 6 days.

I made the change that was suggested and got a four digit year, but the year for January shows up as 2006, not 2007.

I hope that this makes sense and someone can help me help her with this mess. It sounds like she got taken advantage of big time.

Thanks, Kimber

brandonH
05-08-2007, 03:14 AM
yes she did, if the code has a problem, the developer shoud fix it. and next time , come ask here first, she will probably get some free code. There are a few of us on here that would have no problem throwing somethign together for her.

nikkiH
05-08-2007, 11:38 PM
I made the change that was suggested and got a four digit year, but the year for January shows up as 2006, not 2007.



Add bolded line:


startDate.setDate(1); // Calendar start at day 1
startDate.setMonth(tempMonth); // Calendar start at month given
startDate.setYear(thisYear);


Change line (bolded change from year to thisYear)


cal += '<td colspan="' + weekLength + '">';
cal += '<div class="month">' + monthYear[tempMonth] + ' &nbsp;' + thisYear + '</div>' + endCell + endRow;
cal += startRow;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum