Tilted Forum Project Discussion Community  

Go Back   Tilted Forum Project Discussion Community > Interests > Tilted Technology


 
 
LinkBack Thread Tools
Old 07-05-2005, 11:24 AM   #1 (permalink)
Crazy
 
[javascript] - only renders the 2nd time you view the webpage

Hello,

I have a postnuke website that is displaying some straightforward HTML in a part of the page.

The purpose of the code is to take today's date and convert it to another calendar type using some simple calculations. It will then generate a URL based on the date and present it as an a href link. The problem is that it only displays the URL the 2nd time you view the page. The first time you view the site it doesnt' display it, but if you click any link which loads the page again, or just hit reload, it does work fine.

How can I solve this problem?

The html code for displaying it is as follows:

Code:
<script Language="JavaScript" src="/synaxarium/copticDate.js"></script>
<script>
<!-- relative path of files goes between the quotes below -->
document.write("<a href=\"/page.php?synaxarium/" + 
CopticName[CopticMonth].toLowerCase() + "/day" + CopticDay + ".html\">")
<!--document.write(Date + " - " + CopticDate)-->
document.write(CopticDate)
document.write("</a>")
</script>

the file copticDate.js is as follows:

Code:
today = new Date();
week = today.getDay();
day = today.getDate();
imonth = today.getMonth();
iyear = today.getYear();
month = imonth+1;

if (iyear <= 99)
{
    year = iyear + 1900;
}

else if (iyear > 99)
{
    year = iyear;
}

leapcheck1 = year % 4;
leapcheck2 = year % 100;
leapcheck3 = year % 400;


if ((leapcheck1 != 0) || ((leapcheck2 == 0) && (leapcheck3 != 0)))
{
	leap = false;
}
else if ((leapcheck1 == 0) || (leapcheck3 == 0))
     {
	leap = true;
     }

yearb = year + 1;
leapcheck4 = yearb % 4;
leapcheck5 = yearb % 100;
leapcheck6 = yearb % 400;


if ((leapcheck4 != 0) || ((leapcheck5 == 0) && (leapcheck6 != 0)))
{
	leapb = false;
}
else if ((leapcheck4 == 0) || (leapcheck6 == 0))
     {
	leapb = true;
     }


WeekName = new Array(7);

WeekName[0]="Sunday"
WeekName[1]="Monday"
WeekName[2]="Tuesday"
WeekName[3]="Wednesday"
WeekName[4]="Thursday"
WeekName[5]="Friday"
WeekName[6]="Saturday"

CopticName = new Array(14);

CopticName[1]="Tute"
CopticName[2]="Babah"
CopticName[3]="Hatour"
CopticName[4]="Kiahk"
CopticName[5]="Tubah"
CopticName[6]="Amshir"
CopticName[7]="Baramhat"
CopticName[8]="Baramoudah"
CopticName[9]="Bashans"
CopticName[10]="Baounah"
CopticName[11]="Abib"
CopticName[12]="Misra"
CopticName[13]="El-Nasi"

MonthName = new Array(13);

MonthName[1]="January"
MonthName[2]="February"
MonthName[3]="March"
MonthName[4]="April"
MonthName[5]="May"
MonthName[6]="June"
MonthName[7]="July"
MonthName[8]="August"
MonthName[9]="September"
MonthName[10]="October"
MonthName[11]="November"
MonthName[12]="December"


i = 1;
count = 0;

if (month != i)
{
  do
  {
     if ((i == 1) || (i == 3) || (i == 5) || (i == 7) || (i == 8) || (i == 10) || (i == 12))
     {
  	count = count + 31;
     }
     else if ((i == 4) || (i == 6) || (i == 9) || (i == 11))
     {
  	count = count + 30;
     }
     else if ((i == 2) && !leap)
     {
	count = count + 28;
     }
     else if ((i == 2) && leap)
     {
	count = count + 29;
     }

  i++;

  } while (i < month)
}

count = count + day;

g = 1;
CopticMonth = 4;
CopticDay = 23;
CopticYear = year - 284;

if (count != g)
{
    do
    {
        CopticDay++;
        g++;
        
        if (CopticDay == 31)
        {
	    CopticDay = 1;
	    CopticMonth++;
	}
	if ((CopticMonth == 13) && (CopticDay == 6) && !leapb)
	{
	    CopticDay = 1;
	    CopticMonth = 1;
            CopticYear++;
	}
	else if ((CopticMonth == 13) && (CopticDay == 7) && leapb)
	{
	    CopticDay = 1;
	    CopticMonth = 1;
            CopticYear++;
	}
    }  while (g < count)
}

Date = WeekName[week] + ", " + MonthName[month] + " " + day + ", " + year;
CopticDate = CopticName[CopticMonth] + " " + CopticDay + ", " + CopticYear + " AM";
Thank you.
TheProf is offline  
Old 07-06-2005, 07:05 AM   #2 (permalink)
Junkie
 
The script that writes the link is executing before the external script has completely loaded and executed. You should make a function out of the first script and call that function from the second script.
SinisterMotives is offline  
Old 07-06-2005, 07:14 AM   #3 (permalink)
Junkie
 
Better yet, just add your document.write statements to the bottom of the external script and use only one script tag in the HTML page. That will guarantee that everything happens in the correct sequence.
SinisterMotives is offline  
 

Tags
2nd, javascript, renders, time, view, webpage


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 12:47 PM.

Tilted Forum Project

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Search Engine Optimization by vBSEO 3.6.0 PL2
© 2002-2012 Tilted Forum Project

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62