View Full Version : entering time

05-01-2008, 07:44 AM
I want a button on my web page which when clicked inserts the current time in corresponsind text box.

(please note that i dont want to continue showing the current time. When someone clicks the button, the current time at that point is inserted in a text box on the form).

I understand this isnt that tough but i am a newbie with programming :-)

05-01-2008, 07:46 AM
What you have tried so far? homework?

Philip M
05-01-2008, 09:03 AM
Read the Forum Rules re homework. I must be in a relaxed mood today.:cool:

But the following has some deliberate mistakes in it which you must put right. ;)

<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 tim = hh + ":" + mm + ":" + ss;
document.myform.timeDisplay.value = time;


It is your responsibility to die() if necessary….. - PHP Manual

05-01-2008, 12:58 PM
Got a mistake there:

var tim = hh + ":" + mm + ":" + ss;
document.myform.timeDisplay.value = time;

it's either time at the variable definition or tim at the next line.

Philip M
05-01-2008, 01:30 PM
As I said, the code includes some deliberate mistakes. I am willing to help the OP but not serve it up on a plate for him. He is supposed to find out these mistakes for himself.