Can I call javascript into HTML?

liunx

Guest
Hey everyone, Im trying to make a site(duh) and I wanted to have the time and date in a little bar on the site, I really dont care if its in the bar itself, just on top of it is fine. I found a script in particular that has dynamic time without using forms written in javascript but the problem comes into play, I have the page set up with tables and i have a tabled area where I want to put it. QUestion is, how do I put it there? The body.onload doesnt put it where I want it, or it starts the script from the end of the script itself, ive tried taking the part where it starts itself out and putting it in the part of the table where I want to put it, ive also tried such things as function tick;, function tick();, function tick(), javascript: tick(), javascript tick;, javascript tick(); where tick is the name of the javascript function<!--content-->Can you show us the code, then we can probably optimize it to fit for you. :)<!--content-->jsut stick the javascript code where you want it.<br />
<br />
<script type="text/javascript"><br />
<br />
...code here....<br />
</script><br />
<br />
<br />
you must have those for it to work.<!--content--><html><br />
<body><br />
<br />
<div id="Clock" align="Center">&nbsp</div><br />
<br />
<script> (should this be <script language="JavaScript">?)<br />
function tick() {<br />
var hours, minutes, seconds, ap;<br />
var intHours, intMinutes, intSeconds;<br />
var today;<br />
<br />
today = new Date();<br />
<br />
intHours = today.getHours();<br />
intMinutes = today.getMinutes();<br />
intSeconds = today.getSeconds();<br />
<br />
if (intHours == 0) {<br />
hours = "12:";<br />
ap = "A.M.";<br />
} else if (intHours < 12) { <br />
hours = intHours+":";<br />
ap = "A.M.";<br />
} else if (intHours == 12) {<br />
hours = "12:";<br />
ap = "P.M.";<br />
} else {<br />
intHours = intHours - 12<br />
hours = intHours + ":";<br />
ap = "P.M.";<br />
}<br />
<br />
if (intMinutes < 10) {<br />
minutes = "0"+intMinutes+":";<br />
} else {<br />
minutes = intMinutes+":";<br />
}<br />
<br />
if (intSeconds < 10) {<br />
seconds = "0"+intSeconds+" ";<br />
} else {<br />
seconds = intSeconds+" ";<br />
} <br />
<br />
timeString = hours+minutes+seconds+ap;<br />
<br />
Clock.innerHTML = timeString;<br />
<br />
window.setTimeout("tick();", 100);<br />
}<br />
<br />
window.onload = tick;<br />
<br />
</script><br />
</body><br />
</html><br />
<br />
<br />
How can I call it to display the time in a particular place like a cell of a table<!--content-->are you a C programmer? lol<br />
in javascript you dont always have to call your functions.<br />
<br />
what i suggest you do is save that code as a JS file, then you can do this.<br />
<br />
<td><script src=http://www.htmlforums.com/archive/index.php/"clockcode.js" type="text/javascript"></td><br />
<br />
<br />
and then the javascript should appear in that table cell.<br />
<br />
<br />
i think<br />
:D<!--content-->if he was using that code, he would need to do this<br />
<br />
in the head do:<br />
<script src=http://www.htmlforums.com/archive/index.php/"clockcode.js" type="text/javascript"></script><br />
<br />
<br />
then where ever you want it to display in the table:<br />
<td id="Clock">&nbsp;</td><!--content-->Originally posted by n8thegreat <br />
if he was using that code, he would need to do this<br />
<br />
<td id="Clock"><script src=http://www.htmlforums.com/archive/index.php/"clockcode.js" type="text/javascript"></script></td><br />
<br />
<br />
:doh: i knew that<!--content-->It works! Thank you everyone especially n8thegreat for the help, the problem with the JS file was while i took out the HTML code I left the script tags on and that was why it was getting an error<!--content-->
 
Back
Top