View Full Version : today's date in form field

12-28-2005, 05:16 PM

For the date script at above url, what if I want two or more date fields in the same form[same page] showing ALL CURRENT DATE , what to do ?

12-28-2005, 05:30 PM
just like that:

what if I want two or more date fields in the same form[same page] showing ALL CURRENT DATE , what to do ?

What if? :D

What is your aim, after all?

12-28-2005, 05:40 PM
<body onload="SetToToday('FirstSelect'); SetToToday('SecondSelect');">

name the new drop down as 'SecondSelectDay', 'SecondSelectMonth', 'SecondSelectYear'...

and change the onchange call for each drop down...
<SELECT name="SecondSelectMonth" onchange="ChangeOptionDays('SecondSelect')">

do the same for third, fourth, fifth date fields...

12-30-2005, 09:47 PM
Similarly to Nischumacher's solution, except that a number is used inside the name instead of 'first', 'second', etc. This allows a loop to be used...

<script type="text/javascript">
function setDateFields()
for(var index=0; index<5; index++) // Assuming you have 5 sets of date lists
function setToToday(dateField)
// Enter your code from site here...

There's just a few changes that you would need to be aware of doing it this way....

Variable names cannot begin with numbers; hense I started the names with 'Select' and added the numbers to the second position. Thus the drop-down lists get named: 'Select1Day', 'Select1Month', and 'Select1Year' respectively.
Because of the new naming styles, the onchange would get changed to:
I've also put the page's onload inside the <script> tags (which you could place inside the <head> of your page). Thus you won't call onload="..." inside the <body>.

01-06-2006, 06:06 PM

Please review the forum answer to above url and answer:

I do this but,
in frontpage "Preview Mode" appears good(date current for both) but when publish it to www the date is not current for both date fields but 01 jan 2006 ?
also another problem: after pressing "submit" form a "FrontPage Error." appears, well, please test it and view source code at :


01-06-2006, 06:09 PM
Can't you populate the other from the values of the first one?

01-06-2006, 06:24 PM
what you mean , please say it more describetive ?

01-06-2006, 06:26 PM
please say it in more detail

01-06-2006, 06:29 PM
<script type="text/javascript">

var defaultDate = new Date();
var todayStr =

document.forms[0].isToday1.value = todayStr;
document.forms[0].isToday2.value = todayStr;
document.forms[0].isToday3.value = todayStr;

<form name='anyName'>
Today is: <input type=text size=9 name='isToday1' readonly><br>
Today is: <input type=text size=9 name='isToday2' readonly><br>
Today is: <input type=text size=9 name='isToday3' readonly><br>