By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,101 Members | 1,340 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,101 IT Pros & Developers. It's quick & easy.

How to get dynamic yyyymm dropdown field in jsp?

P: 24
Hi,
I have two fields of date in this format yyyymm(from date and to date)
I have the following code:
Expand|Select|Wrap|Line Numbers
  1. function populateYearSelect() 
  2.             { 
  3.                 d = new Date(); 
  4.                 curr_year = d.getFullYear(); 
  5.                // curr_month = d.getMonth();
  6.  
  7.                 for(i = 0; i < 2; i++) 
  8.                 { 
  9.                     document.getElementById('year').options[i] = new Option(curr_year-i,curr_year-i); 
  10.  
  11.                    // document.month.option[curr_month].selected=true;
  12.  
  13.                 } 
  14.  
  15.             } 
This gives me dynamic year(upto current year)..
But as soon as I add the commented code
Expand|Select|Wrap|Line Numbers
  1. // curr_month = d.getMonth();
  2.  // 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,201305,201304,.......,201212,201211, 201210,......& so on..

Can any one help?
Jun 10 '13 #1
Share this Question
Share on Google+
16 Replies


Dormilich
Expert Mod 5K+
P: 8,639
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.
Jun 10 '13 #2

P: 24
@Dormilich..Thanks 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..
Jun 10 '13 #3

Dormilich
Expert Mod 5K+
P: 8,639
isn’t month in a separate <select>?
Jun 10 '13 #4

P: 24
No month should come in the same select as the year...and should come after year
Jun 10 '13 #5

Dormilich
Expert Mod 5K+
P: 8,639
No month should come in the same select as the year
and why do you address the month and year differently, then?
Jun 10 '13 #6

P: 24
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?
Jun 10 '13 #7

Dormilich
Expert Mod 5K+
P: 8,639
How else should I address it?
you said, they were the same <select>, so why should you address them differently?
Jun 10 '13 #8

P: 24
If I use this code
Expand|Select|Wrap|Line Numbers
  1. function populateYearSelect() 
  2.             { 
  3.                 d = new Date(); 
  4.                 curr_year = d.getFullYear(); 
  5.  
  6.                 for(i = 0; i < 2; i++) 
  7.                     document.getElementById('year').options[i] = new Option(curr_year-i,curr_year-i); 
  8.  
  9.                            } 
  10.  
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?
Jun 10 '13 #9

Dormilich
Expert Mod 5K+
P: 8,639
hm, maybe like new Option(""+year+month, ""+year+month)?
Jun 10 '13 #10

P: 24
But I am not getting the month.
Jun 10 '13 #11

Dormilich
Expert Mod 5K+
P: 8,639
how do you know?
Jun 10 '13 #12

P: 24
because it is not displaying it...
If you wanted this output how will you go for it?
Jun 10 '13 #13

Dormilich
Expert Mod 5K+
P: 8,639
like in the code snippet I posted.
Jun 10 '13 #14

P: 24
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..
Jun 10 '13 #15

Dormilich
Expert Mod 5K+
P: 8,639
btw, months in Date go from 0 to 11.

and you can decrement the month by using Date.setMonth()
Jun 10 '13 #16

Rabbit
Expert Mod 10K+
P: 12,359
You need to embed a loop in your year loop to iterate the months.
Jun 10 '13 #17

Post your reply

Sign in to post your reply or Sign up for a free account.