Solved

Date select list always current

Posted on 2010-11-09
4
306 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Update function to validate checkbox is checked 4 74
IP API - need data... 4 23
Help with query 3 23
Query still returning duplicates 5 27
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…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

786 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