Solved

Date select list always current

Posted on 2010-11-09
4
302 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
Comment Utility
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
Comment Utility
-- 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
Comment Utility
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
Comment Utility
Thank You
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
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/…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now