Click to See Complete Forum and Search --> : Help Needed Please!


MattBallington
06-14-2003, 11:06 AM
I reqire this script that counts up to be on one line. Is this possible? If it is possible could someone please let me know how to do it. Thanks!

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
function countup(yr,m,d) {
var today=new Date();
var todayy=today.getYear();

if ((navigator.appName == "Microsoft Internet Explorer") && (todayy < 2000))
todayy="19" + todayy;
if (navigator.appName == "Netscape")
todayy=1900 + todayy;

var todaym=today.getMonth();
var todayd=today.getDate();
var todaystring=montharray[todaym]+" "+todayd+", "+todayy;
var paststring=montharray[m-1]+" "+d+", "+yr;
var difference=(Math.round((Date.parse(todaystring)-Date.parse(paststring))/(24*60*60*1000))*1);
document.write(" " + difference + "");
}
countup(2003,02,20); // Date in format: (year,month,day)
// End -->
</script>

David Harrison
06-14-2003, 02:21 PM
I'm not entirely sure what you mean by count up so I'm not going to try and answer that but I think I have a better way of getting the variable todayy, it goes a little like this:

var todayy=today.getYear();

while(todayy>100){todayy-=100;}
todayy+=2000;

it's just a little shorter is all.

David Harrison
06-14-2003, 02:25 PM
Oh wait, yes I do know what you mean by count up. I think I'll be able to rustle something up if you gimme enough time.

David Harrison
06-14-2003, 03:37 PM
I have enclosed as an attachment what I am pretty sure is what you want, if it isn't let me know and I'll have another stab.

Here's the code not as an attach ment if you want to give it a quick glance:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head><meta http-equiv="content-type" content="text/html; charset=windows-1252">

<title>Time</title>

<script type="text/javascript">

<!-- Begin
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

var today=new Date();
var todayd=today.getDate();
var todaym=today.getMonth();
var todayy=today.getYear();

while(todayy>100){todayy-=100;}
todayy+=2000;

function countup(yr,m,d){

d=d*1;m=m*1;yr=yr*1;

if((d-1)<todayd || (m-1)<todaym || yr<todayy){

var paststring=montharray[m-1]+" "+d+", "+yr;d++;

if((m==1 || m==3 || m==5 || m==7 || m==8 || m==10 || m==12) && d>31){d-=31;m++;}
else if((m==4 || m==6 || m==9 || m==11) && d>30){d-=30;m++;}
else if(m==2 && (yr/4)==(Math.round(yr/4)) && d>29){d-=29;m++;}
else if(m==2 && (yr/4)!=(Math.round(yr/4)) && d>28){d-=28;m++;}
if(m>12){m=1;yr++;}

}

else{paststring=montharray[m-1]+" "+d+", "+yr;return false;}

datecountup.innerHTML=paststring;

setTimeout('countup('+yr+','+m+','+d+')', 1000);}

// End -->

</script>

</head>

<body>

<div id="datecountup"></div>

<script type="text/javascript">countup(2003,02,20);</script>

<p>
<a href="http://validator.w3.org/check/referer"><img
src="http://www.w3.org/Icons/valid-html401"
alt="Valid HTML 4.01!" height="31" width="88"></a>
</p>


</body></html>

MattBallington
06-14-2003, 04:23 PM
Thanks, but the script counts how many days old something is such as how old a website is. And also i mean that can the actuall script go on one line like this:

<SCRIPT LANGUAGE="JavaScript"><!-- Begin var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); function countup(yr,m,d) { var today=new Date(); var todayy=today.getYear(); if ((navigator.appName == "Microsoft Internet Explorer") && (todayy < 2000)) todayy="19" + todayy; if (navigator.appName == "Netscape") todayy=1900 + todayy; var todaym=today.getMonth(); var todayd=today.getDate(); var todaystring=montharray[todaym]+" "+todayd+", "+todayy; var paststring=montharray[m-1]+" "+d+", "+yr; var difference=(Math.round((Date.parse(todaystring)-Date.parse(paststring))/(24*60*60*1000))*1); document.write(" " + difference + ""); } countup(2003,02,20); // Date in format: (year,month,day) // End --></script>

David Harrison
06-14-2003, 04:38 PM
Why would you want to bother with it being on one line, is it just to keep it from cluttering up your page source. If so you could just put it in a separate .js file and use it on all of your pages without having the code on every page.

MattBallington
06-14-2003, 05:05 PM
No, Its because i insert a javascript file into a page, the file is the sidebar (menu) for my site.
Here is an eg of the js file:
//
function writeSideBar() {
document.write('Content Here, This is Where the days old script needs to go and on one line, it think this might be possible')
}


in the body of my html page i have the folloing to insert the js file:
<script language="Javascript">
writeSideBar();
</script>

Im not sure how to get the days old script to work in the js file because its basically in another javascript.

David Harrison
06-14-2003, 05:16 PM
Well as a last ditch effort hows this (download the attachment).

MattBallington
06-15-2003, 12:16 PM
Here is my menu.js file that I insert into my HTML pages:
//
function writeNavBar() {
document.write('<table border="0" width="18%" cellspacing="0" cellpadding="0"><tr><td width="100%"><p align="center"><b>M E N U</b></td></tr><tr><td width="100%">Time:</td></tr><tr><td width="100%">Date:</td></tr><tr><td width="100%">Days Old:</td></tr></table>')
}

I need 3 scripts inside the menu.js fie, they are as follows: Time, Date and Days Old

The Time Script:
Script for the head of a document:

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function MakeArrayday(size) {
this.length = size;
for(var i = 1; i <= size; i++) {
this[i] = "";
}
return this;
}
function MakeArraymonth(size) {
this.length = size;
for(var i = 1; i <= size; i++) {
this[i] = "";
}
return this;
}
function MenuClock() {
if (!document.layers && !document.all)
return;
var runTime = new Date();
var hours = runTime.getHours();
var minutes = runTime.getMinutes();
var seconds = runTime.getSeconds();
var dn = "AM";
if (hours >= 12) {
dn = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
if (minutes <= 9) {
minutes = "0" + minutes;
}
if (seconds <= 9) {
seconds = "0" + seconds;
}
movingtime = "<b>"+ hours + ":" + minutes + ":" + seconds + " " + dn + "</b>";
if (document.layers) {
document.layers.clock.document.write(movingtime);
document.layers.clock.document.close();
}
else if (document.all) {
clock.innerHTML = movingtime;
}
setTimeout("MenuClock()", 1000)
}
window.onload = MenuClock;
// End -->
</script>

The Script For the Body:
<span id=clock style="position:relative;"></span>


This is the date script:
<SCRIPT LANGUAGE="JavaScript1.2">
<!-- Begin
var months=new Array(13);
months[1]="January";
months[2]="February";
months[3]="March";
months[4]="April";
months[5]="May";
months[6]="June";
months[7]="July";
months[8]="August";
months[9]="September";
months[10]="October";
months[11]="November";
months[12]="December";
var time=new Date();
var lmonth=months[time.getMonth() + 1];
var date=time.getDate();
var year=time.getYear();
if (year < 2000)
year = year + 1900;
document.write("<center><b>" + lmonth + " ");
document.write(date + ", " + year + "</b></center>");
// End -->
</SCRIPT>

Here is the days old script:

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
function countup(yr,m,d) {
var today=new Date();
var todayy=today.getYear();

if ((navigator.appName == "Microsoft Internet Explorer") && (todayy < 2000))
todayy="19" + todayy;
if (navigator.appName == "Netscape")
todayy=1900 + todayy;

var todaym=today.getMonth();
var todayd=today.getDate();
var todaystring=montharray[todaym]+" "+todayd+", "+todayy;
var paststring=montharray[m-1]+" "+d+", "+yr;
var difference=(Math.round((Date.parse(todaystring)-Date.parse(paststring))/(24*60*60*1000))*1);
document.write(" " + difference + "");
}
countup(2003,02,20); // Date in format: (year,month,day)
// End -->
</script>

Thanks in advance!!

David Harrison
06-15-2003, 04:45 PM
Do you have a web address for it or failing that could you upload the files.

MattBallington
06-15-2003, 04:59 PM
No, i dont have a website yet, ive just beeing trying to get all this working first.

MattBallington
06-15-2003, 05:07 PM
I have attached the two documents, the page and the .js file.
In the .js file is where the time and date and days old scripts need to be displayed (obviouslly where it says the text)
e.g. Time: (Time Script Here)

David Harrison
06-16-2003, 01:37 PM
How about this then, it's all of your script's, and I have avoided altering them as much as possible. This should be what you want.

MattBallington
06-16-2003, 02:40 PM
Thanks, It works brilliantlly now!
I am now able to customise it and continue with the creation of my site!!

MattBallington
06-16-2003, 03:44 PM
Hi, It works ok, but i have a script which i forgot about:
<script src="http://www.hostedstuff.com/services/counter/?id=358&pic=0"></script>

I have already added it where it needs to be (above the days old in the statistics section) but for some reason it always ends up at the bottom of everything. Do you have any ideas to why this is?

Here is the .js file:
function MakeArrayday(size) {
this.length = size;
for(var i = 1; i <= size; i++) {
this[i] = "";
}
return this;
}
function MakeArraymonth(size) {
this.length = size;
for(var i = 1; i <= size; i++) {
this[i] = "";
}
return this;
}
function MenuClock() {
if (!document.layers && !document.all)
return;
var runTime = new Date();
var hours = runTime.getHours();
var minutes = runTime.getMinutes();
var seconds = runTime.getSeconds();
var dn = "AM";
if (hours >= 12) {
dn = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
if (minutes <= 9) {
minutes = "0" + minutes;
}
if (seconds <= 9) {
seconds = "0" + seconds;
}
movingtime = "<b>"+ hours + ":" + minutes + ":" + seconds + " " + dn + "</b>";
if (document.layers) {
document.layers.clock.document.write(movingtime);
document.layers.clock.document.close();
}
else if (document.all) {
clock.innerHTML = movingtime;
}
setTimeout("MenuClock()", 1000)
}
window.onload = MenuClock;


var months=new Array(13);
months[1]="January";
months[2]="February";
months[3]="March";
months[4]="April";
months[5]="May";
months[6]="June";
months[7]="July";
months[8]="August";
months[9]="September";
months[10]="October";
months[11]="November";
months[12]="December";
var time=new Date();
var lmonth=months[time.getMonth() + 1];
var date=time.getDate();
var year=time.getYear();
if (year < 2000)
year = year + 1900;
datestring="<center><b>" + lmonth + " " + date + ", " + year + "</b></center>";


var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
function countup(yr,m,d) {
var today=new Date();
var todayy=today.getYear();

if ((navigator.appName == "Microsoft Internet Explorer") && (todayy < 2000))
todayy="19" + todayy;
if (navigator.appName == "Netscape")
todayy=1900 + todayy;

var todaym=today.getMonth();
var todayd=today.getDate();
var todaystring=montharray[todaym]+" "+todayd+", "+todayy;
var paststring=montharray[m-1]+" "+d+", "+yr;
difference=(Math.round((Date.parse(todaystring)-Date.parse(paststring))/(24*60*60*1000))*1);
}

countup(2003,02,20); // Date in format: (year,month,day)

function writeSidebar(){

sidebar='<table border="0" width="100%" cellspacing="0" cellpadding="0" background="bg_right.bmp"><tr><td width="100%" align="center" background="titlebg.bmp"><b></b><img border="0" src="timeanddate.bmp" width="131" height="24"></td></tr><tr><td width="100%" align="center"><font class="sidebar"><b>&nbsp;</b></font></td></tr><tr><td width="100%" align="center"><font class="sidebar"><b><span id=clock style="position:relative;"></span></b></font></td></tr><tr><td width="100%" align="center"><font class="sidebar"><b>'+datestring+'</b></font></td></tr><tr><td width="100%" align="center"><font class="sidebar"><b>&nbsp;</b></font></td></tr></table>';
sidebar+='<table border="0" width="100%" cellspacing="0" cellpadding="0" background="bg_right.bmp"><tr><td width="100%" background="titlebg.bmp"><p align="center"><img border="0" src="newsletter.bmp" width="131" height="24"></td></tr><tr><td width="100%"><form method=post action=http://www.ymlp.com/subscribe.php?TheExtremeNetwork><div align="center"><center><table border=0 cellspacing="0" cellpadding="0" width="95%"><tr><td><p align="center"><font class="sidebar"><b>Please Fill Out Your Email Address To Receive The Latest<br>TEN News</b></font></p></td></tr><tr><td><p align="center"><input type=text name=YMP[0] size=20 maxlength=50 style="font-family: Verdana; font-size: 10px"></p></td></tr><tr><td><p align="center"><font size="1"><input type=submit value=Submit name=submit style="font-family: Verdana; font-size: 10px"></font></p></td></tr><tr><td><p align="center"><align="center"><b><font class="sidebar">&nbsp;<br>Privacy Policy</font></b></p></td></tr></table></center></div></form></td></tr></table>';
sidebar+='<table border="0" width="100%" cellspacing="0" cellpadding="0" background="bg_right.bmp"><tr><td width="100%" background="titlebg.bmp"><p align="center"><img border="0" src="statistics.bmp" width="131" height="24"></td></tr><tr><td width="100%"><div align="center"><center><table border="0" width="95%" cellspacing="0" cellpadding="0"><tr><td width="100%"><font class="sidebar"><b><script src="http://www.hostedstuff.com/services/counter/?id=358&pic=0"></script></b></font></td></tr><tr><td width="100%"><font class="sidebar"><b>Days Old:&nbsp;'+difference+'</b></font></td></tr><tr><td width="100%"><font class="sidebar"><b>&nbsp;</b></font></td></tr></table></center></div></td></tr></table>';
sidebar+='More To Go Here';
sidebar+='More To Go Here';
document.write(sidebar);}

David Harrison
06-16-2003, 03:57 PM
I'l have it ready in a few mins with a bit of luck.

May I make a recommendation, when you have the sidebar+="Blahblahblah." at the bottom, if the string is very long spread it out over a few lines so that it is easier to modify.

MattBallington
06-16-2003, 04:10 PM
Ok, Thanks!

David Harrison
06-16-2003, 05:03 PM
Sorry but this is gonna take longer than I anticipated, I may be able to get you an answer after 9:30 English Time (I don't know where you are), but don't hold you're breath because I have two exams tomorrow and then from 7:00 until 9:30 I play badminton. But there's always a chance, so you never know, swing by tomorrow and see.

MattBallington
06-16-2003, 05:07 PM
Thanks, BTW i am in England aswell

David Harrison
06-17-2003, 04:45 PM
Ok, this should do it, it wasn't quite as complicated as I thought.

MattBallington
06-18-2003, 03:30 AM
Thanks For All Of Your Help lavalamp!