Solved

Date select list always current

Posted on 2010-11-09
4
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
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/…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

717 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