Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with years...

    Hi there...I am creating a drop-down with years. Now I need to display 10 years starting from this year so 2007, 2008, 2009...2017. So next year the drop down will show 2008, 2009,....2018...I think year(Date+1) is pretty stupid to try...but I did and offcourse it doesnt work)

    <select name=ExpirationYear class=fields>

    <option></option>
    <option value="Sign In"><%=Year(Date) %></option>
    <option value="Sign In From Unpaid break"><%=Year(Date+1) %></option>
    <option value="Sign Out For Unpaid break">2009</option>
    <option value="Sign Out">2010</option>
    <option value="Sign In">2011</option>
    <option value="Sign In From Unpaid break">2012</option>
    <option value="Sign Out For Unpaid break">2013</option>
    <option value="Sign Out">2014</option>
    <option value="Sign In">2015</option>
    <option value="Sign In From Unpaid break">2016</option>
    <option value="Sign Out For Unpaid break">2017</option>
    <option value="Sign Out">2018</option>

    </select>

    Any clues???

  • #2
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Oops..I got it:)

    Hey there...sorry for posting too soon...looks like i got the answer...silly me...its <%=Year(Date)+2%>

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    uhm, can you just get the value for the current year and then add the neccesary ints? Like:
    Code:
    <select name=ExpirationYear class=fields>
    
    <option></option>
    <%
    thisyear = Year(Date)
    %>
    <option value="Sign In"><%=thisyear%></option>
    <option value="Sign In From Unpaid break"><%= thisyear + 1 %></option>
    <option value="Sign Out For Unpaid break"><%= thisyear + 2 %></option>
    <option value="Sign Out"><%= thisyear + 3 %></option>
    etc....
    </select>
    I am the luckiest man in the world

  • #4
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Ya thats cool...

    Hey Roefl...that works fine too...much neater in fact

  • #5
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    or, the correct way would be to use DateAdd()

    http://www.w3schools.com/vbscript/func_dateadd.asp

  • #6
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Inserting Drop-down Value into DB

    Hey there...still on the drop-down issue, I was trying to insert the drop-down value chosen into the DB...however I am getting an error...is this the right way to do it....

    <%
    thisyear = Year(Date)
    %>

    <select name=ExpYear class=fields>

    <option></option>
    <option value=[COLOR="Red"]'<%=thisyear %>'[/COLOR]><%=thisyear %></option>
    <option value='<%=thisyear+1 %>'><%=thisyear+1 %></option>

    </select>

    The Insert statement is a usual insert on the submit page to which this form redirects and and to get this value I am doing '"& Request("EXPYear")&"'

    Anything wrong???

  • #7
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    can u response.write out the sql statement,
    also, what field type is it being inserted into?

  • #8
    New Coder
    Join Date
    Jan 2007
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Field Type issue

    Hey there... a <% Response.write(Year(Date)+1)%> gives a correct answer...however as you mentioned the field type of the field is varchar and length is 2, whereas I was trying to insert 2007 or 2008. So I will have to do a right something to get only the last 2 digits...

    This seems to work so far...yay
    <option value='<%=right(Year(Date)+1, 2) %>'><%=thisyear+1 %></option>

    Thanks again for your insight angst!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •