Current location: Hot Scripts Forums » General Web Coding » JavaScript » Adding Date/Time Script Problem


Adding Date/Time Script Problem

Reply
  #1 (permalink)  
Old 09-08-09, 10:16 AM
Tony S. Tony S. is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 43
Thanks: 8
Thanked 0 Times in 0 Posts
Adding Date/Time Script Problem

Hello,
How is everyone doing today? I hope all here are well.
As you know by now I am very new to coding of any kind but have been able to get the help i need from members at this forum. I am very thankful,
It seems i need your help again. The problem I am havind is that I have been attemting to add a Date/Time JavaScript To my web page without any success. What happens is when I paste the code into my source page the script is visble but after I try to save the code to that page the code vanishes leaving only a small remenent of the code on the page, needless to say the Date/Time is not displated on my web page. I have put the JavaScript here for your inspection also a portion of my page sorce code after I have tried to save the Date/Time script there. Can any one tell me what i need to do to have this script work on my web page.
I am using cPanel to host my web page. They are set up to accept JavaScript so I don't know why the script disapears of the page.
This is the Date/ Time script
Code:
<script>

/*
Live Date Script- 
© Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions, 100's more DHTML scripts, and Terms Of Use,
visit http://www.dynamicdrive.com
*/


var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","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>
Here Is what my web page source code looks like after i have pasted and tried to save the script to the page:

Code:
<p align="center"><font size="4"><a href="/ohbm/user_login.php"><strong><font color="#000033">Login</font></strong></a>    <a href="/ohbm/user_registration.php?packageval=c4ca4238a0b923820dcc509a6f75849b"><strong><font color="#000033">Sign-Up</font></strong></a>    <a href="/ohbm/Pages/Affiliates.html"><strong><font color="#000033">Affiliates</font></strong></a>    <a href="/ohbm/Pages/Directory.html"><strong><font color="#000066">Submit A Site</font></strong></a>    <a href="/ohbm/Pages/Terms.html"><strong><font color="#000033">Terms</font></strong></a>    <a href="mailto:tony@sasonlinebusinesssuccess.com"><strong><font color="#000066">Contact Us</font></strong></a></font></p><p align="center" /><hr /><p /><p align="center"><em><strong>A Online Home Business Can Easily Make You Rich!!!</strong></em></p><h1 align="center"><font color="#ff0000">&quot;Yes, A Online Home Business Can Easily Earn You  Six Figures A Year Fast<br />At Long Last, You Can Now Get Big Profits From You Own Online Business, Full Or Part Time<br />With Proven Methods, Tactics And Hot Selling Products<br />I Can Quickly And Easily Show You How&quot;</font></h1><p align="justify"><font size="4"></font></p><p /><p align="justify"><font size="4"></font></p><p /><p align="justify"><font size="4"></font></p><p /><p><font size="4"></font></p><p><font size="4"></font></p><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"></font></p><p /><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"></font></p><p /><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"><table align="center" style="WIDTH: 500px" border="0" cellspacing="1" cellpadding="1"><tbody><tr><td></td></tr></tbody></table></font></p><p align="justify"><font size="4">From The Desk Of: <em><strong>Tony Sanford</strong></em> </font></p><p align="justify"><font size="4">Date: <script>

/*
Live Date Script- 
© Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions, 100's more DHTML scripts, and Terms Of Use,
visit http://www.dynamicdrive.com
*/


var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","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></font></p><p align="justify"><font size="4">Dear Fellow Internet Marketer,</font></p><p align="justify">
My Source Code Page After I tried to Save The Date/Time Script:
Code:

<p align="center"><font size="4"><a href="/ohbm/user_login.php"><strong><font color="#000033">Login</font></strong></a>    <a href="/ohbm/user_registration.php?packageval=c4ca4238a0b923820dcc509a6f75849b"><strong><font color="#000033">Sign-Up</font></strong></a>    <a href="/ohbm/Pages/Affiliates.html"><strong><font color="#000033">Affiliates</font></strong></a>    <a href="/ohbm/Pages/Directory.html"><strong><font color="#000066">Submit A Site</font></strong></a>    <a href="/ohbm/Pages/Terms.html"><strong><font color="#000033">Terms</font></strong></a>    <a href="mailto:tony@sasonlinebusinesssuccess.com"><strong><font color="#000066">Contact Us</font></strong></a></font></p><p align="center" /><hr /><p /><p align="center"><em><strong>A Online Home Business Can Easily Make You Rich!!!</strong></em></p><h1 align="center"><font color="#ff0000">&quot;Yes, A Online Home Business Can Easily Earn You  Six Figures A Year Fast<br />At Long Last, You Can Now Get Big Profits From You Own Online Business, Full Or Part Time<br />With Proven Methods, Tactics And Hot Selling Products<br />I Can Quickly And Easily Show You How&quot;</font></h1><p align="justify"><font size="4"></font></p><p /><p align="justify"><font size="4"></font></p><p /><p align="justify"><font size="4"></font></p><p /><p><font size="4"></font></p><p><font size="4"></font></p><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"></font></p><p /><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"></font></p><p /><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"></font></p><p align="justify"><font size="4"><table align="center" style="WIDTH: 500px" border="0" cellspacing="1" cellpadding="1"><tbody><tr><td></td></tr></tbody></table></font></p><p align="justify"><font size="4">From The Desk Of: <em><strong>Tony Sanford</strong></em> </font></p><p align="justify"><font size="4">Date:<script></script> <span id="clock"></span></font></p><p align="justify">
I know it is a lot to look at but I hope you can help me figure this one out.

Thank you
Tony S.

Last edited by Nico; 09-08-09 at 12:17 PM.
Reply With Quote
  #2 (permalink)  
Old 09-09-09, 08:47 PM
ruteckycs's Avatar
ruteckycs ruteckycs is offline
Coding Addict
 
Join Date: Jul 2009
Posts: 377
Thanks: 6
Thanked 10 Times in 10 Posts
You start your script off with

<script>

it should be

<script language="javascript">
Reply With Quote
  #3 (permalink)  
Old 09-10-09, 06:40 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
<script type="text/javascript">
Reply With Quote
  #4 (permalink)  
Old 09-10-09, 08:32 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
I know there are a lot of websites on the internet.
And I know there is old and new information.
The problem is, the old information doesn't tell you about the new information.
You kind of have to just keep up with it.

Your HTML is missing parts and the parts that you do have are old and out dated.
You need to update, start using style sheets and get rid of old depreciated tags.

I rewrote and reorganized your code so it is more up to date.

I added the HTML, HEAD and BODY tags.
I added a style sheet and removed depreciated tags.
Then I put your Javascript inside the HEAD element.

I think you will find that everything works now.
HTML Code:
<html>
<head>
<style>
.container
{
 text-align:center;
 }
.nav_span
{
 color:#003;
 font-size:18;
 font-weight:bold;
 margin-right:10px;
 }
hr
{
 margin-top:15px;
 margin-bottom:20px;
 }
.headline
{
 font-size:2em;
 font-weight:bold;
 color:#f00;
 margin-top:20px;
 }
.signiture
{
 font-size:18;
 text-align:justify;
 margin-top:30px;
 }
.date
{
 font-size:18;
 text-align:justify;
 margin-top:10px;
 }
#clock{font-weight:bold;}
</style>
<script>
var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","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=dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn
 if(document.all){document.all.clock.innerHTML=cdate}
 else if(document.getElementById){document.getElementById("clock").innerHTML=cdate}
 else{document.write(cdate)}
 }
setInterval("getthedate()",1000)
</script>
</head>
<body>
<div class="container">
<a href="/ohbm/user_login.php"><span class="nav_span">Login</span></a>
<a href="/ohbm/user_registration.php?packageval=c4ca4238a0b923820dcc509a6f75849b"><span class="nav_span">Sign-Up</span></a>
<a href="/ohbm/Pages/Affiliates.html"><span class="nav_span">Affiliates</span></a>
<a href="/ohbm/Pages/Directory.html"><span class="nav_span">Submit A Site</span></a>
<a href="/ohbm/Pages/Terms.html"><span class="nav_span">Terms</span></a>
<a href="mailto:tony@sasonlinebusinesssuccess.com"><span class="nav_span">Contact Us</span></a>
</div>
<hr>
<div class="container"><em><strong>An Online Home Business Can Easily Make You Rich!!!</strong></em></div>
<div class="container headline">&quot;Yes, An Online Home Business Can Easily Earn You Six Figures A Year - Fast<br />At Long Last, You Can Now Get Big Profits From Your Own Online Business, Full Or Part Time<br />With Proven Methods, Tactics And Hot Selling Products<br />I Can Quickly And Easily Show You How&quot;</div>
<div class="signiture">From The Desk Of: <em><strong>Tony Sanford</strong></em></div>
<div class="date">Date: <span id="clock"></span></div>
</body>
</html>
__________________
Jerry Broughton
Reply With Quote
  #5 (permalink)  
Old 09-10-09, 09:16 AM
Tony S. Tony S. is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 43
Thanks: 8
Thanked 0 Times in 0 Posts
Hi,
I want to thank you all for all of your help and support with my script problem. You all are truly amazing and I appreciate your time and effort in helping me. I will take all of your advice also take the information as a learning experience hopefully I will be able to help some one else one day.

Thank You
Tony S.
Reply With Quote
  #6 (permalink)  
Old 09-10-09, 11:48 AM
Tony S. Tony S. is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 43
Thanks: 8
Thanked 0 Times in 0 Posts
Hi,
I am back I have tried the solutions given above and none of them seem to work for me. So I now ask if there any reasons why javasript will not work on a webpage. Could there be a browser settings problem or other web page or settings problem that won't allow the script to work on that particular page?
Can anyone help?

Thank you,
Tony S.
Reply With Quote
  #7 (permalink)  
Old 09-10-09, 12:32 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Is javascript disabled?

How are you adding the code to the page? Is it through a GUI or FTP or Dreamweaver or some other tool?

Does view source display the code?
Reply With Quote
  #8 (permalink)  
Old 09-10-09, 01:04 PM
Tony S. Tony S. is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 43
Thanks: 8
Thanked 0 Times in 0 Posts
Hi wirehopper,
i belive javasript is active. How would I check to make sure?
I copy and paste the code from my Windows notepad.
when I check view source the script is there untill I try to save that page then it seems to leave the page some how.
Any Ideas?

Thank You,
Tony S.
Reply With Quote
  #9 (permalink)  
Old 09-10-09, 01:55 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Also note that if a single character is wrong in a script, so you get a syntax error, it can completely crash all scripts on that page. Use the JavaScropt console (Ctrl+Shift+J in FF) or Firebug for FF to see these errors.
Always have reference material near at hand when coding, look in my signature for a few.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
  #10 (permalink)  
Old 09-10-09, 05:40 PM
Tony S. Tony S. is offline
Newbie Coder
 
Join Date: Jul 2009
Posts: 43
Thanks: 8
Thanked 0 Times in 0 Posts
JavaScript not working

Is there any setting on my PC that I may be missing or not working that could cause JavaSript not to work on my web pages? I am using "Windows vista home premium 64 bit" OS.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
file attachment problem on email script sujata_ghosh Perl 2 01-11-07 01:17 AM
Paid job adding features to script. formatc Job Offers & Assistance 1 05-27-06 02:52 PM
Formmail permissions problem... Clark_Kent Perl 4 05-23-06 12:38 PM
Jump.php Script Problem - need help Liz PHP 2 10-08-05 09:53 AM


All times are GMT -5. The time now is 01:54 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.