473,396 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

drop down box upto current year/populate with current month

i have created following drop down box for displaying year... i want to populate the drop down box upto current year.. and need to write a java script for this .. any pointers in this regard will be very helpful
Expand|Select|Wrap|Line Numbers
  1. <select name=year>
  2. <option value=2008>2008</option>
  3. <option value=2007>2007</option>
  4. <option value=2006>2006</option>
  5. </select>
  6.  
Mar 7 '08 #1
6 27099
dlite922
1,584 Expert 1GB
i have created following drop down box for displaying year... i want to populate the drop down box upto current year.. and need to write a java script for this .. any pointers in this regard will be very helpful
Expand|Select|Wrap|Line Numbers
  1. <select name=year>
  2. <option value=2008>2008</option>
  3. <option value=2007>2007</option>
  4. <option value=2006>2006</option>
  5. </select>
  6.  
here's a start...

Expand|Select|Wrap|Line Numbers
  1. function populateYearSelect()
  2. {
  3.     d = new Date();
  4.     curr_year = d.getFullYear();
  5.  
  6.     for(i = 0; i < 3; i++)
  7.     {
  8.         document.getElementById('year').options[i] = new Option(curr_year-i,curr_year-i);
  9.     }
  10. }
[HTML]

<body onLoad="populateYearSelect()">

<select name="year" id="year">
// options generated dynamically
</select>

</body>
[/HTML]

that should be start. i just wrote it off the top of my head so take it and run with it!

Good luck.
Mar 7 '08 #2
here's a start...

Expand|Select|Wrap|Line Numbers
  1. function populateYearSelect()
  2. {
  3.     d = new Date();
  4.     curr_year = d.getFullYear();
  5.  
  6.     for(i = 0; i < 3; i++)
  7.     {
  8.         document.getElementById('year').options[i] = new Option(curr_year-i,curr_year-i);
  9.     }
  10. }
[HTML]

<body onLoad="populateYearSelect()">

<select name="year" id="year">
// options generated dynamically
</select>

</body>
[/HTML]

that should be start. i just wrote it off the top of my head so take it and run with it!

Good luck.
hey thanx i am able to get current year populated by doing some workaround.
Mar 15 '08 #3
I have created a drop down box for displaying month.But I want to show current month in the drop down box .
[HTML]
<select name=month onChange="setMonth(value)">
<option value=01>JAN</option>
<option value=02>FEB</option>
<option value=03>MAR</option>
<option value=04>APR</option>
<option value=05>MAY</option>
<option value=06>JUN</option>
<option value=07>JUL</option>
<option value=08>AUG</option>
<option value=09>SEP</option>
<option value=10>OCT</option>
<option value=11>NOV</option>
<option value=12>DEC</option>
</select>
[/HTML]

Now I need to write a java script so that the drop down box will show intially the current month. For example the current month is march therefore the drop dow box should show intially march as the current month.

Need to know how to start it with java scripts any pointers will be very helpful.
Mar 15 '08 #4
hey thanx i am able to get current year populated by doing some workaround.
thanx for the previous reply the next thing i want is to show current month in the drop down box.

[HTML]
<select name=month onChange="setMonth(value)">
<option value=01>JAN</option>
<option value=02>FEB</option>
<option value=03>MAR</option>
<option value=04>APR</option>
<option value=05>MAY</option>
<option value=06>JUN</option>
<option value=07>JUL</option>
<option value=08>AUG</option>
<option value=09>SEP</option>
<option value=10>OCT</option>
<option value=11>NOV</option>
<option value=12>DEC</option>
</select>

[/HTML]
hope u ll help me here also
:) thnax
Mar 15 '08 #5
Hi ,

I got the solution of this problem
Only need to add following lines of code in the script

curr_month = d.getMonth;
document.month.options[curr_month].selected=true;

thanx for the previous reply the next thing i want is to show current month in the drop down box.

[HTML]
<select name=month onChange="setMonth(value)">
<option value=01>JAN</option>
<option value=02>FEB</option>
<option value=03>MAR</option>
<option value=04>APR</option>
<option value=05>MAY</option>
<option value=06>JUN</option>
<option value=07>JUL</option>
<option value=08>AUG</option>
<option value=09>SEP</option>
<option value=10>OCT</option>
<option value=11>NOV</option>
<option value=12>DEC</option>
</select>

[/HTML]
hope u ll help me here also
:) thnax
Mar 15 '08 #6
Hi ,

I got the solution of this problem
Only need to add following lines of code in the script
Expand|Select|Wrap|Line Numbers
  1. curr_month = d.getMonth;
  2. document.month.options[curr_month].selected=true;
  3.  
I have created a drop down box for displaying month.But I want to show current month in the drop down box .
[HTML]
<select name=month onChange="setMonth(value)">
<option value=01>JAN</option>
<option value=02>FEB</option>
<option value=03>MAR</option>
<option value=04>APR</option>
<option value=05>MAY</option>
<option value=06>JUN</option>
<option value=07>JUL</option>
<option value=08>AUG</option>
<option value=09>SEP</option>
<option value=10>OCT</option>
<option value=11>NOV</option>
<option value=12>DEC</option>
</select>
[/HTML]

Now I need to write a java script so that the drop down box will show intially the current month. For example the current month is march therefore the drop dow box should show intially march as the current month.

Need to know how to start it with java scripts any pointers will be very helpful.
Mar 15 '08 #7

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

Similar topics

4
by: Nanos | last post by:
For the form I need to create drop down select with say five different options. There also should be possibility to enter own option if one is not listed. How can I do it.? Thank you in advance...
2
by: p3x573 | last post by:
Hey everyone, I've been reading over this newsgroup and you all seem like a bunch of very knowledgeable people. So maybe you can point me in the right direction. What I am trying to do is...
3
by: JSubadhra | last post by:
Hi, I am very new to ASP. I am trying to change another person's code. I googled my query and read a lot of ideas. But my problem is as I try to change one thing, someother code gets affected....
3
by: rgsw | last post by:
I would like to create a drop down list in a form. When month is selected I would like information for that month only to show in form. Would I have to connect to a different table for each month? ...
3
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
8
by: dskanth | last post by:
I have 4 drop down lists, namely Location, country, State and City. Ex: Location: Asia, Country: India, State: Andhra Pradesh, City: Hyderabad. If i select any option in the Location drop down...
6
by: olala123 | last post by:
i have created following drop down box for displaying year... i want to populate the drop down box upto current year.. and need to write a java script for this .. any pointers in this regard will be...
5
by: atlanteavila | last post by:
Hello all, I've attached a database here that we're using to register people for a series of classes, for a course that we're offering for pre-baptismal certification. I'm wondering if there...
0
by: alphanj | last post by:
Hi 1-Is there a way to have to make a drop-down field and and populate it using a macro? 2-Is there any way to edit drop-down field code ( I mean { FORMDROPDOWN } not through dialogue box.
1
by: yenom red | last post by:
i have a drop down list tied to a database called location. what i hope to achieve is once a location is selected, my other drop down list will auto-populate a list of department in that location....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.