Hi,
I have two fields of date in this format yyyymm(from date and to date)
I have the following 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 - // 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,201305,201304,.......,201212,201211, 201210,......& so on..
Can any one help?
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.
@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..
Dormilich 8,658
Recognized Expert Moderator Expert
isn’t month in a separate <select>?
No month should come in the same select as the year...and should come after year
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?
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?
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?
If I use this 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?
Dormilich 8,658
Recognized Expert Moderator Expert
hm, maybe like new Option(""+year+month, ""+year+month) ?
But I am not getting the month.
Dormilich 8,658
Recognized Expert Moderator Expert
because it is not displaying it...
If you wanted this output how will you go for it?
Dormilich 8,658
Recognized Expert Moderator Expert
like in the code snippet I posted.
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..
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() Rabbit 12,516
Recognized Expert Moderator MVP
You need to embed a loop in your year loop to iterate the months.
I created a code which gives me yyyymm dynamically upto current year month.. - function dropdown(monthfield, yearfield){
-
var monthtext=['01','02','03','04','05','06','07','08','09','10','11','12'];
-
var today=new Date()
-
var monthfield=document.getElementById(monthfield)
-
var yearfield=document.getElementById(yearfield)
-
var thisyear=today.getFullYear()
-
var thismonth=today.getMonth()
-
-
var id = 0;
-
for (var y=0; y<=20; y++){
-
for (var m=(monthtext.length-1); m>=0; m--, id++){
-
if(m<=thismonth){
-
yearfield.options[id]=new Option(thisyear+"-"+monthtext[m], thisyear+""+monthtext[m])
-
}else{}
-
}
-
thisyear-=1
-
thismonth = 12;
-
}
-
yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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 -...
|
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,...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
| |
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...
| |