...

View Full Version : entering time



phiero21
05-01-2008, 08: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 :-)

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

Philip M
05-01-2008, 10: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;
}

</script>

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

BarrMan
05-01-2008, 01: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, 02: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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum