View Full Version : Date Drop down
christrinder
04-10-2003, 05:47 PM
Hello.
Earlier today, somebody gave me this great little script... apologies, I must have deleted the post and I can't remember who it was. This drop-down works ace, but, what I need it to do extra, is add the year to the value, but not the visible option. So todays option in HTML would look like:
<option value="April 04">April</option>
Any ideas? The script I got earlier is shown below:
Thanks
Chris
- - - - - - - - - - - - -
<select name="compldate2" class="text6">
<%
Dim i2
i2 = 0
do while i2 <= 5
value = Month(DateAdd("m",i2, Now()))
response.write("<option value="& MonthName(value) & ">"& MonthName(value) &"</option>")
i2= i2+1
loop
%>
</select>
Well, i posted that code, buth without the two error (you left out the single quotes that should surround the values). What really strange is that that thread is gone :confused: :confused:
About the years: you can add this to it in the page where you use the value. Like this
variable= request.form ("compldate2") + " " + Right(Year(),2)
or
<select name="compldate2" class="text6" size="1">
<%
Dim i2, value, optionv
i2 = 0
do while i2 <= 5
value = Month(DateAdd("m",i2, Now()))
optionv = MonthName(value) + " " + Right(Year(Now),2)
response.write("<option value='" & optionv & "'>"& MonthName(value) &"</option>")
i2= i2+1
loop
%>
</select>
It is off course 03 instead of 2004. If you need 04, then you need to use the dateadd on that value to.
Right(Year(DateAdd("yyyy",1, Now()),2)
in stead of
Right(Year(Now),2)
christrinder
04-10-2003, 07:42 PM
Thanks Raf... thought it was probably you that posted it.
I haven't tested it cause I'm on a different computer now, but the reason I loved the original script so much was because it knew to go back to January after December... "simple things..." and all that! Will it put the correct year next to the month, i.e.
03 November
03 December
04 January
04 February
or am I going to need to include some sort of if statement? Who the hell invented this silly calendar system anyway... didn't they realise how difficult it would make coding web applications?!!!
I've tested it:D (by reading it)
it will give this for each option
<option value='November 03'>November</option>
When you post, the value will be November 03
It'll keep on running. Even in 2004 etc (until browsers only accept html with values enclosed in double quotes ...)
If you need it in the format you asked in your prevous post, you need
optionv = Right(Year(Now),2) + " " + MonthName(value)
If you want to display it (on screen as a label in that way, then use
optionv instead of MonthName(value)
My question Where did the thread go ??
What did you mean with:
apologies, I must have deleted the post and I can't
christrinder
04-11-2003, 09:12 AM
Thanks Guys, we've cracked it!... I know, probably a simple feat for you pros but I'm chuffed. It means they can't set their business objectives for too far in the future!
One more question though... This is the code I've used - basically what you have given me, but I don't understand what one of the components is... what does the "m" in the [Month(DateAdd("m",i2, Now()))] actually do/mean?
Thanks,
Chris
- - - - - - - -
<select name="compldate2" class="text6">
<%
Dim i2
i2 = 0
do while i2 <= 5
value = Month(DateAdd("m",i2, Now()))
valueyear = Right(Year(DateAdd("m",i2, Now())),2)
response.write("<option value='"& MonthName(value) + " " + Right(Year(Now),2) &"'>"& MonthName(value) + " " + valueyear &"</option>")
i2= i2+1
loop
%>
</select>
You're welcome.
Finaly a coder that actually want's to understand the code.:thumbsup:
See attach for more info on used functions (Dateadd and Monthname). It's some pages from the mse.exe helpfile. If you have MsOffice professional installed, this file is probably also on your machine. Else get it from the cd. It has an excellent helpfunction + it's an ideal and free ASP editor
Pleas answer my questoin from the privious post. Deleted? How?
christrinder
04-11-2003, 01:09 PM
Cheers Raf... that document was ace... never knew ASP made dealing with the calendar so simple!
Yeah I think I must have deleted the original post instead of another. I posted a question, then worked it out myself. So I went back to delete the post so people didn't waste their time trying to help, and I think I must have deleted the wrong one. Sorry!
Regards,
Chris
Didn't know you could do that (deleating thread). I knew you could delete your own post, buth a thread were people replyed on .... It shouldn't possible.
Anyway, glad it helped. Really, search for that mse.exe file(tool is Microsoft Development Environnement) . The helpfunction is real good.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.