<script type="text/javascript">
function display_c(){
var refresh=1000; // Refresh rate in milli seconds
mytime=setTimeout('display_ct()',refresh) }
function display_ct() {
var strcount
var x = new Date()
var x1=x.toUTCString();
document.getElementById('ct').innerHTML = x1;
tt=display_c(); }
</script>
<script type="text/javascript">
function display_year() {
var x = new Date()
var y=x.getFullYear();
document.getElementById('year').innerHTML = y; }
</script>
</head>
<body>
coding…
</body>
</html>
<body onload=display_ct();>
The first javascript works but not the second when they are together. If I have the second one on its own it works OK but not when they are together.
Can anybody guide me to get them to work properly?
<script type="text/javascript">
function display_c(){
var refresh=1000; // Refresh rate in milli seconds
mytime=setTimeout('display_ct()',refresh) }
function display_ct() {
var strcount
var x = new Date()
var x1=x.toUTCString();
document.getElementById('ct').innerHTML = x1;
tt=display_c(); }
function display_year() {
var x = new Date()
var y=x.getFullYear();
document.getElementById('year').innerHTML = y; }
</script>
but it didn’t make any difference. Thanks for your input.
What are you expecting the above code to do that it is not? What errors are you seeing? How are these functions called? Do you have your full code (including html) online somewhere (preferably Codepen or something like it) so we can take a look?
Both are displyed in the footer. The 1st one displays the International Time, and the 2nd one displays the year alongside the Copyright. Some pages don’t have the International Time and the Copyright Year works OK. I have checked both pages and found that I didn’t have the Copyright coding at the bottom like this;
But it still does not work. If I put the Copyright coding at the top, the Copyright year works but the International time does not work. However, that identifies where the problem lies. I have tried combining the two like this;
<body onload=display_ct.year();>
And other modifications, but I can’t get them to work, so I need a Javascript expert. Thanks again for your input.
I could be missing something, but when I use your original code or my rearranged code, I see something like the following. What are you seeing different or what should the code be displaying that it is currently not? Keep in mind, the website name will not show in the footer, because I am not running php locally.
Thank you, everything works good now. I only needed to change the bottom line. I do prefer my method of coding CSS as its much easier to follow & I haven’t yet found a downside.
I now need an expert in BackEnd CodeIgniter, so I hope I can find someone here in FreeCodeCamp!
The problem with writing it all in one line is that it is much more difficult for others to read. If you plan on working with other people at some point, you will need to get used to it written with indentation.