PDA

View Full Version : Putting Today's Date/Time in a FORM Text Box


JillFleming
10-28-2002, 12:38 PM
This code works by itself:
<html>
<head>
<!--
This file retrieved from the JS-Examples archives
http://www.js-examples.com
100s of free ready to use scripts, tutorials, forums.
Author: JS-Examples - http://www.js-examples.com/
-->
<SCRIPT type=text/javascript>
TDay = new Array();
TDay[0] = "Sunday";
TDay[1] = "Monday";
TDay[2] = "Tuesday";
TDay[3] = "Wednesday";
TDay[4] = "Thursday";
TDay[5] = "Friday";
TDay[6] = "Saturday";
TMonth = new Array();
TMonth[0] = "January";
TMonth[1] = "February";
TMonth[2] = "March";
TMonth[3] = "April";
TMonth[4] = "May";
TMonth[5] = "June";
TMonth[6] = "July";
TMonth[7] = "August";
TMonth[8] = "September";
TMonth[9] = "October";
TMonth[10] = "November";
TMonth[11] = "December";
TDate = new Date();
CurYear = TDate.getYear();
CurYear=(CurYear<2000)?1900+CurYear:CurYear;
CurMonth = TDate.getMonth();
CurDayOw = TDate.getDay();
CurDay = TDate.getDate();
TheDate = TDay[CurDayOw] + ', ';
TheDate += TMonth[CurMonth] + ' ';
TheDate += CurDay + ', ';
TheDate += CurYear;

function trackTime()
{
TTime = new Date();
CurHour = TTime.getHours();
CurMin = TTime.getMinutes();
CurSec = TTime.getSeconds();
TheTime = CurHour;// Add them
TheTime += ((CurMin < 10)?':0':':') + CurMin;
TheTime += ((CurSec < 10)?':0':':') + CurSec;
document.examplef.time_box.value = TheTime;
}
setInterval('trackTime()',1000);
</SCRIPT>

</head>
<body>
<script type=text/javascript>
document.write(TheDate+'<BR>');
</script>
<FORM NAME="examplef">
Time : <INPUT type=text NAME="time_box" SIZE=10>
</FORM>

</body>
</html>


When I incorporate into my code as follows, all I can do is Document.write the Date or Time to my Form when launched. I tried to following logic of assigning the balue of the return of the date using the DATE function. I need to capture the exact Time & Date the person opens / submits the form.
Here are the pertinent parts of my form( it has many INPUT tags so I'm only posting the one I am trying to display the date into)

<HTML>
<HEAD>
<TITLE>Broker Letter Form</TITLE>

<SCRIPT type=text/javascript>
var today_date = new Date();
var day = today_date.getDate();
var month = today_date.getMonth();
var year = today_date.getYear();
document.write("The date of today is: "+month +"/" + day + "/" + year);
document.write(today_date);
document.brokerinfo.date_box.value=today_date;
</script>

</HEAD>
<BODY bgColor=#ffffff>



<CENTER><B><FONT size=5><u>
2001 Annual Statement of Securities Holdings and Securities </u></font>
<BR><BR></center>

<font size=4>1. Securitites Accounts Maintained with Broker/Dealer and/or Bank</B></font><br><br>



<form name="brokerinfo" action="mailto:fleming.ja@mellon.com" method="post">
<B>Do You Own any Broker/Bank/Dealer Accounts? </B>

<script type=text/javascript>
document.write(today_date +'<BR>');
document.brokerinfo.date_box.value = today_date;
</script>

<td>Todays Date/Time: <INPUT type="text" name="date_box" size="20"</td></tr>

I have to have the user fillout the form & have it EMail me the values - I must only use browser coding to do this exersize.

Thanks VERY Much

jalarie
10-28-2002, 02:03 PM
The JavaScript to write the date_box.value occurs before date_box has been defined. Move the definition above the write to get it to work.

JillFleming
10-28-2002, 02:11 PM
Originally posted by jalarie
The JavaScript to write the date_box.value occurs before date_box has been defined. Move the definition above the write to get it to work.

That did it! Thank You very much ! I am just learning & did not have enough knowlege to figure that out!