How to get dynamic yyyymm dropdown field in jsp?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shepard
    New Member
    • Feb 2013
    • 24

    How to get dynamic yyyymm dropdown field in jsp?

    Hi,
    I have two fields of date in this format yyyymm(from date and to date)
    I have the following code:
    Code:
    function populateYearSelect() 
                { 
                    d = new Date(); 
                    curr_year = d.getFullYear(); 
                   // curr_month = d.getMonth();
      
                    for(i = 0; i < 2; i++) 
                    { 
                        document.getElementById('year').options[i] = new Option(curr_year-i,curr_year-i); 
                        
                       // document.month.option[curr_month].selected=true;
    
                    } 
                    
                }
    This gives me dynamic year(upto current year)..
    But as soon as I add the commented code
    Code:
    // curr_month = d.getMonth();
     // document.month.option[curr_month].selected=true;
    It fails...
    I need date as follows:
    If year is 2012 & month is june then list should show 201206

    Now current month is june so it should show...201306,2 01305,201304,.. .....,201212,20 1211,201210,... ...& so on..

    Can any one help?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    Can any one help?
    help with what? you didn’t tell what the code actually does and how it is different from what you expect.

    anyways, you should take a look at the Error Console, to check whether there are any JS errors listed.

    Comment

    • Shepard
      New Member
      • Feb 2013
      • 24

      #3
      @Dormilich..Tha nks for the response..

      It does not give any errors.. It simply displays year only...upto current year.. Month is not at all displayed..
      I want it as yyyymm==201206. .

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        isn’t month in a separate <select>?

        Comment

        • Shepard
          New Member
          • Feb 2013
          • 24

          #5
          No month should come in the same select as the year...and should come after year

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            No month should come in the same select as the year
            and why do you address the month and year differently, then?

            Comment

            • Shepard
              New Member
              • Feb 2013
              • 24

              #7
              The problem is it does not display month.. It only displays year..
              Also right now year is displayed only once...In the desired output year should be displayed as many times the month currently is...
              What changes should I make in the code to get my desired output?
              @Dormilich::
              and why do you address the month and year differently, then?
              How else should I address it?

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                How else should I address it?
                you said, they were the same <select>, so why should you address them differently?

                Comment

                • Shepard
                  New Member
                  • Feb 2013
                  • 24

                  #9
                  If I use this code
                  Code:
                  function populateYearSelect() 
                              { 
                                  d = new Date(); 
                                  curr_year = d.getFullYear(); 
                                                   
                                  for(i = 0; i < 2; i++) 
                                      document.getElementById('year').options[i] = new Option(curr_year-i,curr_year-i); 
                                                  
                                             }
                  It gives me years upto 2013(current year)...
                  Now how do I make it show month no. along with the year.. the methods I am trying is not working...
                  Do you know how can I get desired answer?

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    hm, maybe like new Option(""+year+ month, ""+year+mon th)?

                    Comment

                    • Shepard
                      New Member
                      • Feb 2013
                      • 24

                      #11
                      But I am not getting the month.

                      Comment

                      • Dormilich
                        Recognized Expert Expert
                        • Aug 2008
                        • 8694

                        #12
                        how do you know?

                        Comment

                        • Shepard
                          New Member
                          • Feb 2013
                          • 24

                          #13
                          because it is not displaying it...
                          If you wanted this output how will you go for it?

                          Comment

                          • Dormilich
                            Recognized Expert Expert
                            • Aug 2008
                            • 8694

                            #14
                            like in the code snippet I posted.

                            Comment

                            • Shepard
                              New Member
                              • Feb 2013
                              • 24

                              #15
                              I understand how I have to display but I dont know how to get current month in my field and decrement it.. & then when it will reach 01.. year should decrement by 1 and month should become 12..

                              Comment

                              Working...