AnsweredAssumed Answered

JavaScript Timer causes FM to stall

Question asked by PBeyrouty on Jul 1, 2013
Latest reply on Jul 2, 2013 by mikebeargie

I have a small bug that I am hoping someone might be able to help me with. I made a very simple JavaScript timer to display the amount of time spent on a task. Obviously it needs to display through the web viewer. It works well enough, however it sometimes causes Filemaker to get stuck when I attempt to leave the layout, and sometimes when I don't. This happens in FileMaker Pro and Go. Has anyone ever encountered a similar problem? I've added the code below. It currently have a button to display the timer. This is just for the development stage and I'm planning on having it load automatically for users.

 

 

  1. "data:text/html," &"
  2. <html>
  3. <head>
  4. <script type="text/javascript">
  5. function setCount()
  6. {
  7. var start = " & GetAsNumber(TimePoints|Today_Workers::Time.Start) & ";
  8. var d = new Date();
  9. var t = d.getHours()*3600 + d.getMinutes()*60 + d.getSeconds();
  10. var diff = t - start;
  11. var h = Math.floor(diff/3600);
  12. var m = Math.floor( (diff - h*3600)/60);
  13. var s = diff - h*3600 - m*60;
  14. if(h<10) {h='0'+h;}
  15. if(m<10) {m='0'+m;}
  16. if(s<10) {s='0'+s;}
  17. var soFar = h + ':' + m + ':' + s;
  18. document.getElementById('timer').innerHTML = soFar;
  19. var run = setInterval( function(){setCount()},1000);
  20. }
  21. </script>
  22. </head>
  23. <body>
  24. <p align="center">Time so far is: <b id='timer'>??</b>
  25. <input type='button' onclick='setCount()' value='Show the Time'/>
  26. </p>
  27. </body></html>"

Outcomes