?
Solved

Date select list always current

Posted on 2010-11-09
4
Medium Priority
?
310 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 400 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 1600 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

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…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 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