Atypical combination of 3 combo boxes for "Date"...HELP!!!

S

simina

Hi...
Me - Earth.....you - JavaScript...it's the way I see it..
In an Update page, I have 3 combos that work together: 1-Year,2-Month
and the third is Day.
Being in Update "mode", the initial info in these combos is coming
from an Access db, for ex.: 2004 6 26.
Now, if the user wants to change that date, he starts with the Year
(hopefully...), then it's the Month and then the Day. After he's
choosing the month, the third combo - Day combo - should show only 30
or 31 or 29 or 28 days depending on the year(leap or not) and the
month.
BUT, the day should still be the same - 26- in its combo (because
maybe, the user doesn't want to change the day, but only the year and
the month), with a few exceptions:
in the Day combo it should appear just the first line of the combo
which is exactly the string 'Day' if:
1. the Day that's coming from the db is 31 AND the Month is nr 2 or 4
or 6 or 9 or 11 (where 11 for ex, is November);
2. the Day that's coming from the db is 30 AND the Month is nr 2;
3. the Day that's coming from the db is 29 AND the Month is nr 2 AND
Year%4 different than zero (leap year)

It's hysterical, right?
Now, I do have a function that is populating the combos depending on
the Year and Month but I just can't figure out how can I keep the day
value in the combo even after I choose an year and a month....

Here is the function:
function defineDate(frm,i)
{
var myMonth = eval("frm.myMonth" + i + ".value");//frm.myMonth1.value
var myYear = eval("frm.myYear" + i + ".value");//frm.myYear1.value

if(myMonth==1 || myMonth==3 || myMonth==5 || myMonth==7 ||
myMonth==8 || myMonth==10 || myMonth==12)
{
for(j=0; j<=31; j++)
(eval("frm.myDay" + i)).options[1] = null;
for(j=1; j<=31; j++)
(eval("frm.myDay" + i))[eval("frm.myDay" + i).length] = new
Option(j,j);
}
else if((myMonth == 2) && ((myYear%4) == 0)){
for(j=0; j<=31; j++)
(eval("frm.myDay" + i)).options[1] = null;
for(j=1; j<=29; j++)
(eval("frm.myDay" + i))[eval("frm.myDay" + i).length] = new
Option(j,j);
}
else if((myMonth == 2) && ((myYear%4) != 0)){
for(j=0; j<=31; j++)
(eval("frm.myDay" + i)).options[1] = null;
for(j=1; j<=28; j++)
(eval("frm.myDay" + i))[eval("frm.myDay" + i).length] = new
Option(j,j);
}
else{
for(j=0; j<=31; j++)
(eval("frm.myDay" + i)).options[1] = null;
for(j=1; j<=30; j++)
(eval("frm.myDay" + i))[eval("frm.myDay" + i).length] = new
Option(j,j);
}

return false;
}

I have this kind of notation ("frm.myDay" + i) because this Date field
made by 3 combos is a user-defined field and the user might have up to
10 fields like this in his page.
So, I had to attach an 'i' to each name of the combo.

Here is the code for combos in the form page (in ColdFusion, by the
way):

<cfset myMonth = #Month(DateFormat(CreateODBCDate(getMyValue.ValueText),
"dd/mm/yyyy"))#>
<cfset myDay = #Day(DateFormat(CreateODBCDate(getMyValue.ValueText),
"dd/mm/yyyy"))#>
<cfset myYear = #Year(DateFormat(CreateODBCDate(getMyValue.ValueText),
"dd/mm/yyyy"))#>
<tr>
<td><!--- UDC name --->
#addMyControls.ControlName#
</td>
<td><!--- create the DATE combos --->
<select name="myYear#i#" onChange="return defineDate(this.form,#i#);">
<option value="year">Year</option>
<cfloop index="z" from="2000" to="2020">
<option value="#z#"<cfif #z# EQ #myYear#>SELECTED</cfif>>#z#</option>
</cfloop>
</select>

<select name="myMonth#i#" onChange="return
defineDate(this.form,#i#);">
<option value="month">Month</option>
<cfloop index="x" from="1" to="12">
<option value="#x#"<cfif #x# EQ
#myMonth#>SELECTED</cfif>>#x#</option>
</cfloop>
</select>

<select name="myDay#i#">
<option value="day">Day</option>
<cfloop index="y" from="1" to="31">
<option value="#y#"<cfif #y# EQ #myDay#>SELECTED</cfif>>#y#</option>
</cfloop>
</select>

<input type="hidden" name="dateI" value="#i#">
<script language="JavaScript1.2">
dateI[dateI.length]=#i#;
</script>

I hope I explained well and I can get some help.....
Thank you,
Simina
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top