Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

Set the current year as the default

Hi
i have a drop down menu with a number of years in it and i want to set the default year to the current year.
How do i go about this?

my select statement is:

    <b>Year:&nbsp;&nbsp;&nbsp; </b>
            <select name="Year" size="1">
          <option>--Select one--</option>
          <option>2003</option>
          <option>2004</option>
          <option>2005</option>
          <option>2006</option>
          <option>2007</option>
          <option>2008</option>
          <option>2009</option>
          <option>2010</option>
          <option>2011</option>
          <option>2012</option>
          <option>2013</option>
          <option>2014</option>
          <option>2015</option>
          <option>2016</option>
          <option>2017</option>
          <option>2018</option>
          <option>2019</option>
          <option>2020</option>
     </select>

0
alkam
Asked:
alkam
1 Solution
 
randhawaCommented:
u must use the asp functions "now" with the some checks
0
 
KovisCommented:
<script>
function SelectYear() {
 var now = new Date();
 Year.value=now.getYear();
}
</script>
<body onLoad="SelectYear()">

You have to add values to your options also:

<option value="2003">2003</option>
<option value="2004">2004</option>
...
0
 
alkamAuthor Commented:
perfect!
cheers
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now