Assign value to TextBox on page load using JavaScript or jQuery

Last Reply on Dec 13, 2016 11:27 PM By maideen

Posted on Dec 13, 2016 02:53 AM

Mr.Mudassar

I have some javascript code to find the local computer date and time. because our server in US. We are in Malaysia. It picks up the US Time. Below code is display on page only. I need to store the result into mssql database table  so i need to display the result in text box control.

Pls advice me.

thank you

Maideen

<script type="text/javascript">
   var currentTime = new Date()
   var month = currentTime.getMonth()
   var day = currentTime.getDate()
   var year = currentTime.getFullYear()
   var hours = currentTime.getHours()
   var minutes = currentTime.getMinutes()
   var seconds = currentTime.getSeconds()
   var miliseconds = currentTime.getMilliseconds()

   if (minutes < 10) {
       minutes = "0" + minutes
   }
   if (seconds < 10) {
       seconds = "0" + seconds
   }
   document.write(year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds + ":" + miliseconds)
</script>

 

 

You are viewing reply posted by: maideen on Dec 13, 2016 11:27 PM.
Posted on Dec 13, 2016 11:27 PM

Mr.Dharmedr.

Thanks working fine.

I am using master page. So I just change your code like this

document.getElementById('<%= txtConvertTime.ClientID %>').value = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds + ":" + miliseconds;

 

thank you very much...

maideen