title: How do I call a JavaScript function from an html.erb
body: <p>How do I call a JavaScript function from html.erb</p>
  
  <p>in <strong>application.js</strong></p>
  
  <pre><code>function displayClock() {
    var digital = new Date();
    var hours = digital.getHours();
    var minutes = digital.getMinutes();
    var seconds = digital.getSeconds();
    var amOrPm = 'AM';
    if (hours &gt; 11) amOrPm = 'PM';
    if (hours &gt; 12) hours = hours - 12;
    if (hours == 0) hours = 12;
    if (minutes &lt;= 9) minutes = '0' + minutes;
    if (seconds &lt;= 9) seconds = '0' + seconds;
    dispTime = '&lt;b&gt;'+hours + ':' + minutes + ':' + seconds + ' ' + amOrPm+'&lt;/b&gt;';
    document.getElementById('time').innerHTML = dispTime;
    setTimeout('displayClock()', 1000);
  }
  </code></pre>
  
  <p>and in <strong>home.html.erb</strong> </p>
  
  <pre><code>displayClock();
  </code></pre>
  
  <p>but it's not calling function!</p>