Solved

Date select list always current

Posted on 2010-11-09
4
307 Views
Last Modified: 2012-06-27
For credit card exp dates:
I'd like to have 2 date select lists, one for month and one for year that will always be current.
0
Comment
Question by:webdork
  • 2
4 Comments
 
LVL 3

Assisted Solution

by:Epitel0920
Epitel0920 earned 100 total points
ID: 34094954
Use DateTime.Now to get the current date on the page_load.

Then use code to populate the two select lists as such.
selectList => items.
items.Add(new SelectListItem        {            Text = "January",            Value = "1",            Selected = true        });
0
 
LVL 7

Accepted Solution

by:
dxdinh earned 400 total points
ID: 34095023
-- something like this? select the current with the current year + 3???

<html>
<head>

  <script language="javascript" type="text/javascript">

  function windowOnLoad ()
  {
      var currentTime = new Date();
      var month = currentTime.getMonth() ;      
      var year  = currentTime.getFullYear ();      
      // adding 3 more years
      for (i=0;i<3;i++)
      {              
            var objOption = new Option (year, year ) ;
            document.getElementById('year').options[i] = objOption;
            year++;
      }
      // setting up 12 months
      for (j=0;j<=12;j++)
      {
            
            var objOption = new Option (j+1, j+1 ) ;
            document.getElementById('month').options[j] = objOption;
      }
      //select the current month
      document.getElementById('month').value = month;
      
  }
      
  </script>
</head>

<body onLoad="windowOnLoad();">
   <select id="year">
      <option> </option>
   </select>
   <br>
   <select id="month">
      <option> </option>
   </select>
   
   
</body>
</html>
0
 
LVL 3

Expert Comment

by:Epitel0920
ID: 34095071
Also when add the onSelectValueChanged. On the selectList for the current year add from current month to december. When the value of the year is changed to not be the current year add all 12 months to the month selectList.
0
 

Author Closing Comment

by:webdork
ID: 34096434
Thank You
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question