0

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.

    <html>
    <head>
    <script>          
       
function checkTime(i)
{
    if (i<10)
{
       i="0" + i;
    }
    return i;
      }
function checkMsec(j)
 {
        if ( (j<100) && (j<10))
        {
        j="00" + j;
     }
        if ((j<100) && (j>10))
        {
     j="0" + 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+"-"+cMon+"-"+cYear+" "+h+":"+m+":"+s+":"+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
      
      }
    </script>
    </head>
    <body>
 <form name ="frm1" method ="POST" action="<% gait_url %>">

     <p>Time 1: <input type="button" name=start1 value= "Start" id="start1" onClick ="timeCheck(this)">

     <input type="button" name=stop1 id="stop1" value= "Stop" onClick ="timeCheck(this)"></p>

     <p>Time 2: <input type="button" name=start2 value= "Start" id="start2" onClick ="timeCheck(this)">

     <input type="button" name=stop2 id="stop2" value= "Stop" onClick ="timeCheck(this)">   </p>

<input type="submit" value="Back to Menu" name="Back to Menu">

</form>

    </body>
    </html>

1 Answer 1

1

The return value goes to the object's event method, not to the objects property "id".

Change this

stTime = cDat+"-"+cMon+"-"+cYear+" "+h+":"+m+":"+s+":"+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

to

stTime.id = cDat+"-"+cMon+"-"+cYear+" "+h+":"+m+":"+s+":"+ms;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.