This works until I bring in my clock. Why?

I'm using an app called Zing Charts which works fine. It looks like this:

<script src="http://cdn.zingchart.com/zingchart.min.js"></script>
<script>
var chartData={
 "type": "line",  "series": [
 { "values": [35, 42, 67, 89, 25, 34, 67, 85 ] } ]
 };
 window.onload=function(){
zingchart.render({
id:'chartDiv',
height:400,
width:600,
data:chartData
  });
  };
  </script>

...and then you just throw in a div within the body and BAM - a great looking graph.

In an effort to implement this into an already existing site, I couldn't get it to work despite the code being sound. By process of elimination, I came across this:

<body onLoad="startclock()">

When I changed that to <body>, my chart rendered fine. So I'm thinking there's some kind of conflict between Zing Chart and the script for my clock, but I don't know how to code things in way where the two are willing to play nice with one another.

The clock code is this:

<SCRIPT LANGUAGE="JavaScript">
		<!--  Clock --
		var timerID = null
		var timerRunning = false

		function stopclock(){
			if(timerRunning)
				clearTimeout(timerID)
			timerRunning = false
		}

		function startclock(){
			stopclock()
			showtime()
		}

		function showtime(){
			var now = new Date()
			var hours = now.getHours()
			var minutes = now.getMinutes()
			var seconds = now.getSeconds()
			var timeValue = "" + ((hours > 12) ? hours - 12 : hours)
			timeValue  += ((minutes < 10) ? ":0" : ":") + minutes
			timeValue  += ((seconds < 10) ? ":0" : ":") + seconds
			timeValue  += (hours >= 12) ? " P.M." : " A.M."
			document.clock.face.value = timeValue 
			timerID = setTimeout("showtime()",1000)
			timerRunning = true
		}
		//-->
		</SCRIPT>

Open in new window


...and the library that Zing Charts is referenced as part of the code I have above.

What's the conflict and how can I fix it?
brucegustPHP DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Duy PhamFreelance IT ConsultantCommented:
window.onload and <body onload="..."> are two different ways to handle the same event. So if you have both, depending on the order you put the scripts, then the later handler will be used. If your window.onload is put before <body onload="...">, then <body onload="..."> will be used, else your window.onload will be used.

You should consider calling startclock() from window.onload, and of course remove onload="..." from <body>.

...
<script>
 var chartData={
  "type": "line",  "series": [
  { "values": [35, 42, 67, 89, 25, 34, 67, 85 ] } ]
  };
  window.onload=function(){
 zingchart.render({
 id:'chartDiv',
 height:400,
 width:600,
 data:chartData
   });
 startclock();
   };
   </script>

<body>
...
</body>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brucegustPHP DeveloperAuthor Commented:
Perfect!

Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.