473,511 Members | 14,846 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get dynamic yyyymm dropdown field in jsp?

24 New Member
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
17 4486
Dormilich
8,658 Recognized Expert Moderator Expert
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
Shepard
24 New Member
@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
8,658 Recognized Expert Moderator Expert
isn’t month in a separate <select>?
Jun 10 '13 #4
Shepard
24 New Member
No month should come in the same select as the year...and should come after year
Jun 10 '13 #5
Dormilich
8,658 Recognized Expert Moderator Expert
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
Shepard
24 New Member
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
8,658 Recognized Expert Moderator Expert
How else should I address it?
you said, they were the same <select>, so why should you address them differently?
Jun 10 '13 #8
Shepard
24 New Member
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
8,658 Recognized Expert Moderator Expert
hm, maybe like new Option(""+year+month, ""+year+month)?
Jun 10 '13 #10
Shepard
24 New Member
But I am not getting the month.
Jun 10 '13 #11
Dormilich
8,658 Recognized Expert Moderator Expert
how do you know?
Jun 10 '13 #12
Shepard
24 New Member
because it is not displaying it...
If you wanted this output how will you go for it?
Jun 10 '13 #13
Dormilich
8,658 Recognized Expert Moderator Expert
like in the code snippet I posted.
Jun 10 '13 #14
Shepard
24 New Member
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
8,658 Recognized Expert Moderator Expert
btw, months in Date go from 0 to 11.

and you can decrement the month by using Date.setMonth()
Jun 10 '13 #16
Rabbit
12,516 Recognized Expert Moderator MVP
You need to embed a loop in your year loop to iterate the months.
Jun 10 '13 #17
Sherin
77 New Member
I created a code which gives me yyyymm dynamically upto current year month..

Expand|Select|Wrap|Line Numbers
  1. function dropdown(monthfield, yearfield){
  2.                var monthtext=['01','02','03','04','05','06','07','08','09','10','11','12'];
  3.                var today=new Date()
  4.                var monthfield=document.getElementById(monthfield)
  5.                var yearfield=document.getElementById(yearfield)
  6.                var thisyear=today.getFullYear()
  7.                var thismonth=today.getMonth()
  8.  
  9.                var id = 0;
  10.                for (var y=0; y<=20; y++){
  11.                    for (var m=(monthtext.length-1); m>=0; m--, id++){
  12.                        if(m<=thismonth){
  13.                            yearfield.options[id]=new Option(thisyear+"-"+monthtext[m], thisyear+""+monthtext[m])
  14.                        }else{}
  15.                    }
  16.                    thisyear-=1
  17.                    thismonth = 12;
  18.                }
  19.                yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year
  20.            }
  21.  
Dec 10 '20 #18

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

Similar topics

8
10194
by: Lisa | last post by:
I have a drop down that defaults to "select" after the page refreshes. How do I keep the selected value in the dropdown field... I've tried EVERYTHING and nothing works! :( <script...
5
2957
by: Ganco | last post by:
We have a dropdown combobox, where some of the text is wider than the textarea. I cannot set the width of the SELECT any higher due to design restrictions on the company website. When clicking...
4
29513
by: Dabbler | last post by:
I have two tables I'm editing in a Gridview. The VANS table contains a key to the other LESSOR table. I would like to use a dropdown list to select the LessorId value while displaying the Lessor...
0
2895
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
2
1582
by: SF | last post by:
Hi, I am new to ASP.NET. I have started to create a new ASP.NET web. I can succesfully insert a table into a form but my form does not look good becuase some filed (from table) are foreigh key...
0
1021
by: premkutuva | last post by:
I have created a run time dropdown control in the serverside ASPX file also, i want to creat event handle for that control also i need to handle the OnItemChange( ) event. in server side aspx file,...
1
2688
by: SunshineInTheRain | last post by:
The following code is dynamic create dropdownmenu which data within pulled from database However, the code work well on IE but not on Firefox. On Firefox, the whole mouseover and mouseout function...
4
2795
by: mainul05 | last post by:
hi, i m newbie php+mysql. in i have the following problem. i tried my best to solve it but could do it. please help me. i have a from where 3 fields are STATE, AREA and SUBRUB. AREA is connected...
8
2305
by: klbrownie | last post by:
I am trying to create a report that asks the user to select the report option from a drop down field. The field is based on field in a form, which pulls its options from a table. Source Table -...
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1583
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.