ThreadBoard ArchivesSite FeaturesActiveworlds SupportHistoric Archives |
Javascript (General Discussion)
Javascript // General DiscussiondionAug 21, 2002, 10:10pm
Can someone tell me what's wrong with this script?
<script language="JavaScript"> //This Script creates variables for the date and time that is displayed in the upper right hand corner function makeArray() { for (i = 0; i<makeArray.arguments.length; i++) this[i + 1] = makeArray.arguments[i]; } var months = new makeArray('January','February','March','April','May','June','July','August', 'September','October','November','December'); var date = new Date(); var dd = date.getDate(); if (dd == 1 || dd == 21 || dd == 31) { day = dd + "st"; } else { if (dd == 2 || dd == 22) { day = dd + "nd"; } else { if (dd == 3 || dd == 23) { day = dd + "rd"; } else { day = dd + "th"; } var month = date.getMonth() + 1; var yy = date.getYear(); var year = (yy < 1000) ? yy + 1900 : yy; var hh = date.getHours(); var hour = (hh > 12) ? hh - 12 : hh; var mm = date.getMinutes(); if (mm < 10) { minute1 = "0" + mm; } minute1 = "" + minute1 if (hh < 12) { minute = minute1 + " AM" } else { minute = minute1 + " PM" } </script> Thanks, -Dion makiAug 21, 2002, 10:45pm
who knows...but would
<body onLoad="goforit()"> <script> var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" ) var montharray=new Array("January","February","March","April","May","June","July","August","Sep tember","October","November","December") function getthedate(){ var mydate=new Date() var year=mydate.getYear() if (year < 1000) year+=1900 var day=mydate.getDay() var month=mydate.getMonth() var daym=mydate.getDate() if (daym<10) daym="0"+daym var hours=mydate.getHours() var minutes=mydate.getMinutes() var seconds=mydate.getSeconds() var dn="AM" if (hours>=12) dn="PM" if (hours>12){ hours=hours-12 } if (hours==0) hours=12 if (minutes<=9) minutes="0"+minutes if (seconds<=9) seconds="0"+seconds //change font size here var cdate="<small><font color='000000' face='Arial'><b>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn +"</b></font></small>" if (document.all) document.all.clock.innerHTML=cdate else if (document.getElementById) document.getElementById("clock").innerHTML=cdate else document.write(cdate) } if (!document.all&&!document.getElementById) getthedate() function goforit(){ if (document.all||document.getElementById) setInterval("getthedate()",1000) } </script> <span id="clock"></span> work for you? ;-) lol maki goober kingAug 22, 2002, 10:25am
Umm, why would you need a function to create an array? Can't you just
create the array directly, like so? var months = new Array('January','February','March','April','May','June','July','August', 'September','October','November','December'); --or-- var months = ['January','February','March','April','May','June','July','August', 'September','October','November','December']; As for what's wrong with it, I suspect it's your else-if statements. Instead of looking like this: if (dd == 1 || dd == 21 || dd == 31) { day = dd + "st"; } else { if (dd == 2 || dd == 22) { day = dd + "nd"; } It should look like this: if (dd == 1 || dd == 21 || dd == 31) { day = dd + "st"; } else if (dd == 2 || dd == 22) { day = dd + "nd"; } Hope that helped! :) [View Quote] > Can someone tell me what's wrong with this script? > > <script language="JavaScript"> > //This Script creates variables for the date and time that is displayed in > the upper right hand corner > function makeArray() { > for (i = 0; i<makeArray.arguments.length; i++) > this[i + 1] = makeArray.arguments[i]; > } > > var months = new > makeArray('January','February','March','April','May','June','July','August', > 'September','October','November','December'); > var date = new Date(); > var dd = date.getDate(); > if (dd == 1 || dd == 21 || dd == 31) { > day = dd + "st"; > } else { > if (dd == 2 || dd == 22) { > day = dd + "nd"; > } else { > if (dd == 3 || dd == 23) { > day = dd + "rd"; > } else { > day = dd + "th"; > } > var month = date.getMonth() + 1; > var yy = date.getYear(); > var year = (yy < 1000) ? yy + 1900 : yy; > var hh = date.getHours(); > var hour = (hh > 12) ? hh - 12 : hh; > var mm = date.getMinutes(); > if (mm < 10) { > minute1 = "0" + mm; > } > minute1 = "" + minute1 > if (hh < 12) { > minute = minute1 + " AM" > } else { > minute = minute1 + " PM" > } > </script> > > Thanks, > -Dion > > > -- Goober King Would help if he knew what it was being used for... robrod at prism.net kahAug 22, 2002, 2:56pm
"dion" <Dion at digevo.net> wrote in
news:3d642bdb$1 at server1.Activeworlds.com: > Can someone tell me what's wrong with this script? ><<snip script>> If you've got access to PHP and if it's not meant to be updating every second you could make life easier for yourself and use this code: <?php echo date("jS o\f F Y g:i A", time()); ?> today at 1PM it would return: 22nd of August 2002 1:00 PM To get it working, just place that code in the place you want the date and time printed and rename the file to .php (if PHP is available). KAH dionAug 22, 2002, 3:43pm
dionAug 22, 2002, 3:44pm
But that will default to the server's time and I want it to be the time that
is on the user's computer so that it shows their the time based on their timezone. [View Quote] goober kingAug 22, 2002, 6:14pm
What sort of error messages is it giving you? (If you're using Netscape,
type "javascript:" in the Location box after running the script, otherwise you can double click on the yellow warning triangle in the lower-left corner of IE to find out the errors) [View Quote] > It didn't fix it :-\ > [View Quote] -- Goober King Nothing more troubling than broken Javascript that gives no errors... robrod at prism.net ncc 72897Aug 22, 2002, 9:08pm
<html><head>
<SCRIPT LANGUAGE="JavaScript"> <!-- function NowDate() { var now = new Date(); hr = now.getHours(); min = now.getMinutes(); sec = now.getSeconds(); days = now.getDay(); day = now.getDate(); month = now.getMonth(); year = now.getYear(); if (year < 0) {year = year + 100} wkdays = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday' ); months = new Array('January','February','March','April','May','June','July','August','Sep tember','October','November','December'); if (day == 1 || day == 21 || day == 31) {day = day + "st"} else if (day == 2 || day == 22) {day = day + "nd"} else if (day == 3 || day == 23) {day = day + "rd"} else {day = day + "th"} now = null; if (min < 10) {min = "0" + min} if (sec < 10) {sec = "0" + sec} if (hr < 10) {hr = " " + hr} CurTime = wkdays[days] + ", " + day + " " + months[month] + " " + year; document.all.date.innerHTML = CurTime; CurTime = hr + ":" + min + ":" + sec; document.all.time.innerHTML = CurTime; setTimeout("NowDate()", 1000) } //--> </SCRIPT> <BODY BGCOLOR=#000000 OnLoad="NowDate();"> <FONT COLOR=F6D000 id=time></FONT><BR> <FONT COLOR=F6D000 id=date></FONT><BR> </body></html> neo dunceAug 22, 2002, 9:18pm
Try something like this:
<script language="JavaScript"> var days=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday' ); var months=new Array('January','February','March','April','May','June','July','August','Sep tember','October','November','December'); var today=new Date(); var month=months[today.getMonth()]; var dayName=days[today.getDay()]; var day=today.getDate(); var hour=today.getHours(); var minute=today.getMinutes(); document.write(dayName+' '+month+' '+day+' - '+hour+':'+minute); </script> Ok, so it doesn't have all of the 'st', 'rd', stuff in it. But it works.... -dunce [View Quote] goober kingAug 23, 2002, 12:42am
*smacks NCC* Bad NCC, BAD! Those verdammt
document.all.date/time.innerHTML statements only work in IE! If you're going to use those, then you need to check the user's browser and use an NS alternative snippit of code. Either that, or don't use them in the first place. If Dion could tell me where he got his code, I'd be able to explain what went wrong and it won't have to come to that. (provided, of course, that it worked on the site he stole it from. :P) [View Quote] > <html><head> > <SCRIPT LANGUAGE="JavaScript"> > <!-- > function NowDate() { > var now = new Date(); hr = now.getHours(); min = now.getMinutes(); sec = > now.getSeconds(); > days = now.getDay(); day = now.getDate(); month = now.getMonth(); year = > now.getYear(); > if (year < 0) {year = year + 100} > wkdays = new > Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday' > ); > months = new > Array('January','February','March','April','May','June','July','August','Sep > tember','October','November','December'); > if (day == 1 || day == 21 || day == 31) {day = day + "st"} > else if (day == 2 || day == 22) {day = day + "nd"} > else if (day == 3 || day == 23) {day = day + "rd"} > else {day = day + "th"} > now = null; > if (min < 10) {min = "0" + min} > if (sec < 10) {sec = "0" + sec} > if (hr < 10) {hr = " " + hr} > CurTime = wkdays[days] + ", " + day + " " + months[month] + " " + year; > document.all.date.innerHTML = CurTime; > CurTime = hr + ":" + min + ":" + sec; > document.all.time.innerHTML = CurTime; > setTimeout("NowDate()", 1000) > } > //--> > </SCRIPT> > <BODY BGCOLOR=#000000 OnLoad="NowDate();"> > <FONT COLOR=F6D000 id=time></FONT><BR> > <FONT COLOR=F6D000 id=date></FONT><BR> > </body></html> > > > -- Goober King Give him cross-browser compatibility, or give him death! robrod at prism.net shredAug 23, 2002, 1:07am
"Give him cross-browser compatibility, or give him death!"
You might find this of interest, and might even want to promote the campaign by displaying one of its images on your site(s). http://www.anybrowser.org/campaign/ [View Quote] goober kingAug 23, 2002, 9:49am
Though I agree with the sentiment, I can't guarantee my pages will work
in *ALL* browsers, just NS and IE. I can only test my pages on browsers I actually have, and I'm not about to load up my comp with a ton of browsers just to test a few pages. :P [View Quote] > "Give him cross-browser compatibility, or give him death!" > > You might find this of interest, and might even want to promote the > campaign by displaying one of its images on your site(s). > > http://www.anybrowser.org/campaign/ > > [View Quote] -- Goober King Smacking the IEgnorant masses since 1996. robrod at prism.net dionAug 23, 2002, 11:42am
doesn't have an error at all but nothing comes up where it's supposed to. It
did that a few times before as I was working with the script but this time I can't figure out the problem. [View Quote] dionAug 23, 2002, 11:44am
agent1Aug 23, 2002, 1:01pm
Then just make them compatible with one of the HTML 4.0 standards. If a
browser doesn't comply, too bad for them ;) -Agent1 [View Quote] dionAug 23, 2002, 1:21pm
LOL, they can get the information from other places on the internet. It's
you that ends up losing a visitor. Plus using the more compatible stuff tends to work better with future versions and is generally faster. [View Quote] kahAug 23, 2002, 4:32pm
"dion" <Dion at digevo.net> wrote in
news:3d6522ed$1 at server1.Activeworlds.com: > But that will default to the server's time and I want it to be the > time that is on the user's computer so that it shows their the time > based on their timezone. It's achievable with a bit more work (I know you're not going to use this, but I might as well post it anyway). If your site includes user registration, you can ask them what timezone they live in, and use some other date functions to find the server's TZ and compare it to the user's. Mail or reply for code :-)) KAH shredAug 23, 2002, 5:06pm
By doing that much, you're covering the majority of Internet users out there. It if works in Mozilla/Netscape, IE, and even Opera, it'll probably work in anything that conforms to an inkling of HTML standard.
[View Quote] dionAug 23, 2002, 6:19pm
Nahh, if I ever for whatever reason make a registration form, I still want
people to see the time without logging in. [View Quote] kahAug 24, 2002, 11:07am
"dion" <Dion at digevo.net> wrote in
news:3d6698c8$1 at server1.Activeworlds.com: > Nahh, if I ever for whatever reason make a registration form, I still > want people to see the time without logging in. Cookies taste good :-)) KAH dionAug 24, 2002, 6:01pm
kahAug 25, 2002, 8:36pm
"dion" <Dion at digevo.net> wrote in news:3d67e60a at server1.Activeworlds.com:
> Well, they don't work for people who haven't already registered. :-P Anchors with references are tasty as well... [date] <a href="setdatestuff.php" title="Set your date preferences (time zone, etc)">Set date preferences</a>. KAH |