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

Discussion in 'Javascript' started by simina, Sep 16, 2004.

  1. simina

    simina Guest

    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
     
    simina, Sep 16, 2004
    #1
    1. Advertising

  2. JRS: In article <>,
    dated Thu, 16 Sep 2004 09:19:48, seen in news:comp.lang.javascript,
    simina <> posted :

    >Me - Earth.....you - JavaScript...it's the way I see it..


    Read the newsgroup FAQ; see below - p.6, #DDD. It's not a good idea.

    --
    © John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
    <URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
     
    Dr John Stockton, Sep 16, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard A. DeVenezia

    Weird atypical - can new() be old ?

    Richard A. DeVenezia, May 4, 2004, in forum: Java
    Replies:
    1
    Views:
    342
    Joona I Palaste
    May 4, 2004
  2. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,367
    Michael Borgwardt
    May 30, 2004
  3. dthmtlgod

    Fill Combo Box based on another Combo Box

    dthmtlgod, Nov 16, 2005, in forum: ASP General
    Replies:
    1
    Views:
    622
    Bob Barrows [MVP]
    Nov 16, 2005
  4. SM
    Replies:
    2
    Views:
    401
  5. Richard
    Replies:
    5
    Views:
    154
    Richard Cornford
    Aug 12, 2007
Loading...

Share This Page