...

Date to a text box

BillL
06-20-2002, 09:25 PM
I am trying to figure out a way that when a page loads it pulls the date and time into a text box.

Any ideas....

Thanks

Rikimaru
06-20-2002, 09:29 PM
Super simplified version:


<head>

function plugTime(){

t = new Date()

//format how you like

document.form1.timeField.value = t
}


</head>



<body onload = "plugTime()">
...
<form name = 'form1'>
<input type="text" name = "timeField" value ="">
</form>
...
</script>

BillL
06-20-2002, 09:41 PM
Thanks... that worked great.

How can I format it to mm/dd/yy??????

whammy
06-21-2002, 01:28 AM
<form name="myform">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td> <input type="text"
name="thedate"
size="11"
maxlength="10"
style="background:#cccccc; color:#000000; border style:1px solid #666666; text-align:center; font-weight:normal; font-size:12px"
>
</input>
</td>
</tr>
<tr>
<td> <input type="text"
name="time"
size="11"
maxlength="11"
style="background:#cccccc; color:#000000; border style:1px solid #666666; text-align:center; font-weight:normal; font-size:12px"
>
</input>
</td>
</tr>
</table>
</form>

<script language="javascript">
<!--
function showdate(){
var thedate=new Date();
var mymonth=thedate.getMonth()+1;
var mydate=thedate.getDate();
var myyear=thedate.getFullYear();
if(mymonth<10){
mymonth="0"+mymonth;
}
if(mydate<10){
mydate="0"+mydate;
}
mynewdate=mymonth+"/"+mydate+"/"+myyear;
var thefield=document.myform.thedate;
thefield.value=mynewdate;
thefield.blur();
setTimeout("showdate()",1000);
}
showdate()
// -->
</script>

<script>
<!--
function showtime(){
var meridian="AM";
var mydate=new Date();
var myhours=mydate.getHours();
var myminutes=mydate.getMinutes();
var myseconds=mydate.getSeconds();
if (myhours>11){
myhours-=12;
meridian="PM";
}
if(myhours==0){
myhours=12;
}
if(myminutes<10){
myminutes="0"+myminutes;
}
if(myseconds<10){
myseconds="0"+myseconds;
}
mynewtime=myhours+":"+myminutes+":"+myseconds+" "+meridian;
var thefield=document.myform.time;
thefield.value=mynewtime
thefield.blur();
setTimeout("showtime()",1000)
}
showtime()
//-->
</script>


:D



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum