title: how to return the output of a JS function to an HTML button 'id'
body: <p>I have an html page that needs to store the time at the point of button click back on to the database. I have a JS function that calculate the time.But somehow the  html button is not holding the value.Here is the code.</p>
  <pre><code>    &lt;html&gt;
      &lt;head&gt;
      &lt;script&gt;          
         
  function checkTime(i)
  {
      if (i&lt;10)
  {
         i=&quot;0&quot; + i;
      }
      return i;
        }
  function checkMsec(j)
   {
          if ( (j&lt;100) &amp;&amp; (j&lt;10))
          {
          j=&quot;00&quot; + j;
       }
          if ((j&lt;100) &amp;&amp; (j&gt;10))
          {
       j=&quot;0&quot; + j;
           }
          return j;
        }   
      function timeCheck(stTime)
        {
       var currentTime=new Date();
       var cDat = currentTime.getDate();
           var cMon = currentTime.getMonth() + 1; 
           var cYear = currentTime.getFullYear();
           var h = currentTime.getHours();
           var m = currentTime.getMinutes();
           var s = currentTime.getSeconds();
       var ms = currentTime.getMilliseconds();
      
        m = checkTime(m);
        s = checkTime(s);
        ms = checkTime(ms);
        stTime = cDat+&quot;-&quot;+cMon+&quot;-&quot;+cYear+&quot; &quot;+h+&quot;:&quot;+m+&quot;:&quot;+s+&quot;:&quot;+ms;
        //alert(stTime); // this is displaying the time as an alert
        return stTime; //Here I am expecting the id attribute of the button will have the stTime
        
        }
      &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
   &lt;form name =&quot;frm1&quot; method =&quot;POST&quot; action=&quot;&lt;% gait_url %&gt;&quot;&gt;
  
       &lt;p&gt;Time 1: &lt;input type=&quot;button&quot; name=start1 value= &quot;Start&quot; id=&quot;start1&quot; onClick =&quot;timeCheck(this)&quot;&gt;
  
       &lt;input type=&quot;button&quot; name=stop1 id=&quot;stop1&quot; value= &quot;Stop&quot; onClick =&quot;timeCheck(this)&quot;&gt;&lt;/p&gt;
  
       &lt;p&gt;Time 2: &lt;input type=&quot;button&quot; name=start2 value= &quot;Start&quot; id=&quot;start2&quot; onClick =&quot;timeCheck(this)&quot;&gt;
  
       &lt;input type=&quot;button&quot; name=stop2 id=&quot;stop2&quot; value= &quot;Stop&quot; onClick =&quot;timeCheck(this)&quot;&gt;   &lt;/p&gt;
  
  &lt;input type=&quot;submit&quot; value=&quot;Back to Menu&quot; name=&quot;Back to Menu&quot;&gt;
  
  &lt;/form&gt;
  
      &lt;/body&gt;
      &lt;/html&gt;
  </code></pre>