Jump to content

Can't Get Javascript to Work


Egghead

Recommended Posts

Hey all, well I have a really basic webpage on my computer right now that I am working on, adding various things to learn and practice and experiment. Anyhow, I tried adding in some Javascript code and, well, some works and some doesn't. For example, when I add in the first example, the "Hello World!" code, that works fine right now, and the CSS allows the text of it to show (because the page has a colored background).But then when I try to add the code that shows a clock, nothing happens. I added the code in the proper areas, and tried different things, but still, nothing. What am I doing wrong that won't let this more advanced code work? My page has a black background, but I tried changing it to white again just to see if the clock was in fact working, but was being hid, but this wasn't the case either.Any advice is appreciated, thanks,---Egghead---

Link to comment
Share on other sites

I have a really basic clock code here.

<HTML> <HEAD> <TITLE>Title</TITLE> <script TYPE="TEXT/JAVASCRIPT"> function startTime() { var today=new Date() var h=today.getHours() var m=today.getMinutes() var s=today.getSeconds() // add a zero in front of numbers<10 m=checkTime(m) s=checkTime(s) document.getElementById('txt').innerHTML=h+":"+m+":"+s t=setTimeout('startTime()',500) } function checkTime(i) { if (i<10) {i="0" + i} return i } </SCRIPT> </HEAD> <BODY ONLOAD="startTime()"> <div id="txt"> Here the clock comes</div> </BODY> </HTML>

Link to comment
Share on other sites

The clock code from the example above won't work for me either. Here is what I do: I copy-pasted it into Wordpad, saved it as "TestClock.html" and then tried to open it in AOL. It just takes me to a page filled with a paragraph of garbage though. Anyone know what I'm doing wrong?Thanks,---Egghead---

Link to comment
Share on other sites

  • 2 weeks later...

Argh, I still can't get it work. I have it saved in a .html file, am I doing everything right? I try to open it in Internet Explorer 7, which then blocks the content and shows me a page of garbage, then asks if I want to allow the blocked content, I say yes, refresh the page, but it's still garbage :)I am positive it is just something incredibly STOOOPID and I am just too inexperienced programming-wise to figure it out right now :)

Link to comment
Share on other sites

Hmm...well, I inserted it to my site, just to check it, and it works fine with me...Here's the link (at the bottom)Code again:

<html><head><title>Clock</title><script type="text/javascript"> function startTime() { var today=new Date() var h=today.getHours() var m=today.getMinutes() var s=today.getSeconds() // add a zero in front of numbers<10 m=checkTime(m) s=checkTime(s) document.getElementById('txt').innerHTML=h+":"+m+":"+s t=setTimeout('startTime()',500) } function checkTime(i) { if (i<10) {i="0" + i} return i } </script></head><body onload="startTime()"><div id="txt">Do not change the name of this div! Or the names in the JS script, UNLESS you know what you're doing;)</div></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...