Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Set default date in form box 1

Status
Not open for further replies.
Mar 14, 2002
711
US
I have a simple form which is populated from a Javascript pop-up calendar, but before the user enables the calendar and selects a date, is there a way I can set "Today's Date" in the form so that it always displays a current date before the user actually selects the date?

Thanks for any help on this,
 
i found this, i havent tried it. hope it helps

<SCRIPT LANGUAGE="JavaScript"><!--
function padout(number) { return (number < 10) ? '0' + number : number; }

var today = new Date()

var ftoday = padout(today.getDate()) + '/' + padout((today.getMonth() + 1)) + '/' + today.getYear()

var output = '<FORM><SELECT>';

for (var i=-7; i<7; i++) {
aday = new Date(today.getYear(),today.getMonth(),today.getDate() + i)
faday = padout(aday.getDate()) + '/' + padout((aday.getMonth() + 1)) + '/' + aday.getYear()

output += '<OPTION ';

if (faday==ftoday)
output += ' SELECTED';

output += '>' + faday;
}

output += '<\/SELECT><\/FORM>';

document.write(output);
//--></SCRIPT>


Aaron Taylor
John Mutch Electronics
 
It does display the current date in a separate form and when I tried to change this:

var output = '<FORM><SELECT>';

to this:

var output = InputForm.Day;

It still would not insert the current date in to my existing form (Day) :- ( , I am sure I am missing something, any ideas??
 
This is what I ended up doing instead (not sure why I did not think of this before - duh).

I saved the page as an ASP page and made the change:

<INPUT NAME="Day" value="<%=Date()%>" style="font-weight: 700" size="20"><b><img src="show-calendar.gif" width="24" height="22" border="0" onclick="show_calendar('InputForm.Day')"></b></td>

As you can see I added value="<%=Date()%>" which will automatically display today's date in the form and then user can select a date from the pop-up calendar, but the form is now at least not blank. Your suggestion brought me on to the right path, so thanks Aaronjme!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top