Thread: inserting time
View Single Post
  #1 (permalink)  
Old May 1st, 2008, 09:55
phiero21 phiero21 is offline
New Member
Join Date: May 2008
Location: Indian
Age: 28
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
inserting time

I want a button on my website which when clicked inserts the current time in corresponding textarea.

Please note that i dont want to keep showing teh current time. I want the current time to be inserted in the textbox when the button is clicked.

Here is the code what i tried. Please highlight any errors to make it work correctly:
Code: Select all
<form name = "myForm">
<input type = "button" value = "Click To Insert Current Time" onclick = "setClock()">
<input type = "text" name = "timeDisplay">

<script type="text/javascript">
function setClock() {
var today = new Date();
var hh = today.getHours();
if (hh <10) {hh = "0" + hh};
var mm = today.getMinutes();
if (mm <10) {mm = "0" + mm};
var ss = today.getSeconds();
if (ss <10) {ss = "0" + ss};
var time = hh + ":" + mm + ":" + ss;
document.myform.timeDisplay.value = time;
}
</script>

Last edited by Aso; May 2nd, 2008 at 20:08. Reason: Use [code] tags
Reply With Quote