Jump to content

javascript attached file not works


684425

Recommended Posts

Code works when...

<script type="text/javascript">
var currenttime = '<?php print gmdate('F d, Y H:i:s', time() + (1 * 60 * 60))?>'
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")
var serverdate=new Date(currenttime)
function padlength(what){
return (what.toString().length==1)? "0"+what : what
}
function displaytime(){
serverdate.setSeconds(serverdate.getSeconds()+1)
var datestring=montharray[serverdate.getMonth()]+" "+padlength(serverdate.getDate())+", "+serverdate.getFullYear()
var timestring=padlength(serverdate.getHours())+":"+padlength(serverdate.getMinutes())+":"+padlength(serverdate.getSeconds())
document.getElementById("servertime").innerHTML=datestring+" "+timestring
}
window.onload=function(){
setInterval("displaytime()", 1000)
}
</script>

Code not works when...

<script type="text/javascript" src="clock.js">

I want to use second option. Any help?

Link to comment
https://forums.phpfreaks.com/topic/293222-javascript-attached-file-not-works/
Share on other sites

Are you inserting that code at the exact same place? Sometimes the JS needs to be rendered before the ID.

 

Is your clock.js in the same directory? Is it being called?

 

If your on chrome go to dev tools and refresh and see if it's getting called.

 

Edit: Oh I see, it's because you're using php for inline variables. You need to pass them through a parameter function instead if you want to use that js externally.

<script type="text/javascript" src="clock.js">

That assumes "clock.js" is in the same directory as the actual script being executed, which is probably not the case. Use a full path to clock.js, or a URL, like src="/assets/js/clock.js" or "http://yoursite.com/assets/js/clock.js".

<script type="text/javascript" src="clock.js">
That assumes "clock.js" is in the same directory as the actual script being executed, which is probably not the case. Use a full path to clock.js, or a URL, like src="/assets/js/clock.js" or "http://yoursite.com/assets/js/clock.js".

 

<script type="text/javascript" src="clock.js">
<script type="text/javascript" src="tip.js">

both these files are in same directory along with index.php

tip.jis is working fine but clock.js don't work.

 

You said "you're using php for inline variables. You need to pass them through a parameter function instead"

how can i do this?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.