D
David
Hi,
I have a code for filling a dropdown, but I cannot work out how to make
it fill with every date, including todays date, as required below
i.e.
05/10/2006
06/10/2006
07/10/2006
08/10/2006
09/10/2006
10/10/2006
11/10/2006
12/10/2006
13/10/2006
14/10/2006
It needs to display about 10 dates
------------------------------------
The code I have is:
<script type="text/javascript" language="javascript">
function formatDate(t_date, format)
{
/* t_date is expected to be a Date() and format is a string */
var r_date = null; /* string to return */
/* add more formats as desired */
switch (format)
{
case ("mm/dd/yyyy"):
tmp = t_date.getDate();
tmp = tmp<10?"0"+tmp:tmp;
r_date = tmp+"/";
tmp = t_date.getMonth()+1;
tmp = tmp<10?"0"+tmp:tmp;
r_date += tmp+"/"+t_date.getFullYear();
break;
default:
alert("That is not a valid format");
}
return r_date;
}
function addDays(t_date,days)
{
return new Date(t_date.getTime() + days*24*60*60*1000);
}
function fillIt()
{
var s = document.forms["formname"].elements["Date"];
var o;
var theDate = new Date();
var i;
for (i=0; i<20; i++)
{
/* if this is a Tuesday (2) or Thursday (4), put in option, else
add a
day and check again */
while (theDate.getDay() != 0 )
theDate = addDays(theDate, 1);
/* we get here, it's either Tursday or Thursday - write option,
increment, and loop */
tmp = formatDate(theDate, "mm/dd/yyyy");
o = new Option(tmp, tmp);
s.options = o;
theDate = addDays(theDate,1);
}
}
</script>
-----------------------------------
Appreciate your help, thanks
David
I have a code for filling a dropdown, but I cannot work out how to make
it fill with every date, including todays date, as required below
i.e.
05/10/2006
06/10/2006
07/10/2006
08/10/2006
09/10/2006
10/10/2006
11/10/2006
12/10/2006
13/10/2006
14/10/2006
It needs to display about 10 dates
------------------------------------
The code I have is:
<script type="text/javascript" language="javascript">
function formatDate(t_date, format)
{
/* t_date is expected to be a Date() and format is a string */
var r_date = null; /* string to return */
/* add more formats as desired */
switch (format)
{
case ("mm/dd/yyyy"):
tmp = t_date.getDate();
tmp = tmp<10?"0"+tmp:tmp;
r_date = tmp+"/";
tmp = t_date.getMonth()+1;
tmp = tmp<10?"0"+tmp:tmp;
r_date += tmp+"/"+t_date.getFullYear();
break;
default:
alert("That is not a valid format");
}
return r_date;
}
function addDays(t_date,days)
{
return new Date(t_date.getTime() + days*24*60*60*1000);
}
function fillIt()
{
var s = document.forms["formname"].elements["Date"];
var o;
var theDate = new Date();
var i;
for (i=0; i<20; i++)
{
/* if this is a Tuesday (2) or Thursday (4), put in option, else
add a
day and check again */
while (theDate.getDay() != 0 )
theDate = addDays(theDate, 1);
/* we get here, it's either Tursday or Thursday - write option,
increment, and loop */
tmp = formatDate(theDate, "mm/dd/yyyy");
o = new Option(tmp, tmp);
s.options = o;
theDate = addDays(theDate,1);
}
}
</script>
-----------------------------------
Appreciate your help, thanks
David