All source code in ASP/ VbScript Ask a ASP/ VbScript Pro Discussion Forum Categories All jobs in ASP/ VbScript
Quick Search for:  in language:    
probably,been,done,million,times,another,vari
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 281,486. lines
 Jobs: 101. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login

NEW! LEARNING CENTER
Special educational offers, white papers, webcasts, podcasts

  NEW! Download Rational Performance Tester V8 (download now)
  NEW! Download Rational Functional Tester V8 (download now)
  NEW! Download Rational Service Tester for SOA Quality V8 (download now)
  NEW! Teleconference: Quality In Action - Using Rational Quality Manager with Functional, Performance and Web Service Testing Products (download now)
  NEW! Introducing IBM Rational AppScan Developer Edition – easing security testing by non-security professionals (download now)

 

 


Latest postings for ASP/ VbScript.
Click here to see a screenshot of this code!Mess Officer Management System (Sistem Pengurusan Mess Pegawai)
By Mohd Fauzi on 11/23

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

Another date drop down creator

Print
Email
 
VB icon
Submitted on: 5/7/2001 4:01:26 PM
By: Devin Garlit  
Level: Beginner
User Rating: By 3 Users
Compatibility:ASP (Active Server Pages), HTML, VbScript (browser/client side)

Users have accessed this code 34831 times.
 
(About the author)
 
     This has probably been done a million times but this is another variant of how to create dropdowns for the month, day and year. It bases the days on the month and year, so the user won't select day 31 for february. I'm happy to say I wrote this in <a href='http://www.developerspad.com'>Developers Pad</a>.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    '**************************************
    ' Name: Another date drop down creator
    ' Description:This has probably been don
    '     e a million times but this is another va
    '     riant of how to create dropdowns for the
    '     month, day and year. It bases the days o
    '     n the month and year, so the user won't 
    '     select day 31 for february. I'm happy to
    '     say I wrote this in <a href='http://w
    '     ww.developerspad.com'>Developers Pad&
    '     lt;/a>.
    ' By: Devin Garlit
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/vb/scripts/Sho
    '     wCode.asp?txtCodeId=6644&lngWId=4    'for details.    '**************************************
    
    <SCRIPT language=javascript>
    function fnSubmit(strPage)
    {
    document.forms[0].action= strPage
    document.forms[0].submit()	
    }
    </SCRIPT>
    <%
    'here is the call
    writedropdowns
    ''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''
    'writeDropDowns
    'purpose - write three drop down boxes w
    '     here the days available are based on mon
    '     th and year
    'notes - this submits to the page each t
    '     ime a month or year is selected and reca
    '     lculates the number
    'of days 
    '-I use a javascript function to submit 
    '     my form, this may seem a bit much
    'but it allows me to customize better, I
    '     f i want I can throw other validation in
    '     it, or
    'a frame target
    'by: Devin Garlit dgarlit@hotmail.com
    ''''''''''''''''''''''''''''''''''''''''
    '''''''''''''''''''''''''
    Sub writeDropDowns()
    Dim strSelfLink
    strSelfLink = request.servervariables("SCRIPT_NAME")
    response.Write "<FORM name=dates method=post>" & vbcrlf
    response.Write MonthDropDown("month1",False,request("month1"),strSelfLink) & " " & DayDropDown("day1", "",getDaysInMonth(request("month1"),request("year1")),request("day1")) & " " & YearDropDown("year1","","", request("year1"),strSelfLink) & vbcrlf
    response.Write "</FORM>"	& vbcrlf
    End Sub
    		
    'MonthDropDown
    'strName = name of drop down
    'blnNum = 'If blnNUM Is True, Then show 
    '     As numbers
    'strSelected = the currenct selected mon
    '     th
    'strSelfLink = link to current page
    function MonthDropDown(strName, blnNum, strSelected, strSelfLink)
    Dim strTemp, i, strSelectedString			
    strTemp = "<Select name='" & strName& "' onchange='javascript: fnSubmit(" & chr(34) & strSelfLink & chr(34) & ")'>" & vbcrlf
    strTemp = strTemp & "<OPTION value='" & 0 & "'>" & "Month" & "</OPTION>" & vbcrlf			
    For i = 1 To 12
    if strSelected = CStr(i) Then
    	strSelectedString = "Selected"
    Else
    	strSelectedString = ""
    End if
    			
    if blnNum Then
    strTemp = strTemp & "<OPTION value='" & i & "' " & strSelectedString & " >" & i & "</OPTION>" & vbcrlf			
    Else
    	strTemp = strTemp & "<OPTION value='" & i & "' " & strSelectedString & " >" & MonthName(i) & "</OPTION>" & vbcrlf			
    End if
    Next					
    strTemp = strTemp & "</Select>" & vbcrlf	
    MonthDropDown = strTemp
    End function
    'YearDropDown
    'strName = name of dropdown
    'intStartYear = year to start options li
    '     st
    'intEndYear = year to end options list
    'strSelected = the currenct selected yea
    '     r
    'strSelfLink = link To currentpage
    function YearDropDown(strName, intStartYear, intEndYear, strSelected, strSelfLink)
    
    Dim strTemp, i, strSelectedString	
    
    if intStartYear = "" Then
    intStartYear = Year(now())
    End if	
    	
    if intEndYear = "" Then
    intEndYear = Year(now()) + 9
    End if
    	
    strTemp = "<Select name='" & strName& "' onchange='javascript: fnSubmit(" & chr(34) & strSelfLink & chr(34) & ")'>" & vbcrlf			
    strTemp = strTemp & "<OPTION value='" & 0 & "'>" & "Year" & "</OPTION>" & vbcrlf			
    For i = intStartYear To intEndYear		
    if strSelected = CStr(i) Then
    strSelectedString = "Selected"
    Else
    strSelectedString = ""
    End if
    strTemp = strTemp & "<OPTION value='" & i & "' " & strSelectedString & " >" & i & "</OPTION>" & vbcrlf							
    Next					
    strTemp = strTemp & "</Select>" & vbcrlf	
    YearDropDown = strTemp
    End function
    'DayDropDown
    'strName = name of drop down
    'intStartDay = day to start with
    'intEndDay = day to end with
    'strSelected = current slected day
    function DayDropDown(strName, intStartDay, intEndDay, strSelected )
    	Dim strTemp, i, strSelectedString	
    	if intStartDay = "" Then
    	 intStartDay = 1
    	End if	
    	
    	if intEndDay = "" Then
    	 intEndDay = getDaysInMonth(Month(now()),Year(now())) 
    	End if
    	
    	strTemp = "<Select name='" & strName& "'>" & vbcrlf			
    	strTemp = strTemp & "<OPTION value='" & 0 & "'>" & "Day" & "</OPTION>" & vbcrlf			
    	For i = intStartDay To intEndDay
    	 if strSelected = CStr(i) Then
    	strSelectedString = "Selected"
    	 Else
    	strSelectedString = ""
    	 End if
    	 strTemp = strTemp & "<OPTION value='" & i & "' " & strSelectedString & " >" & i & "</OPTION>" & vbcrlf							
    	Next					
    	strTemp = strTemp & "</Select>" & vbcrlf	
    	DayDropDown = strTemp
    End function
    'getDaysInMonth
    'strMonth = month as number
    'strYear = year
    function getDaysInMonth(strMonth,strYear)
    		Dim strDays	 
    Select Case CInt(strMonth)
    Case 1,3,5,7,8,10,12:
    		strDays = 31
    Case 4,6,9,11:
    	strDays = 30
    Case 2:
    		if ( (CInt(strYear) Mod 4 = 0 And CInt(strYear) Mod 100 <> 0) Or ( CInt(strYear) Mod 400 = 0) ) Then
    		 strDays = 29
    		Else
    		 strDays = 28
    		End if	
    'Case Else:
    End Select 
    getDaysInMonth = strDays
    End function	
    %>	
    	


Other 4 submission(s) by this author

 

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
7/29/2001 4:49:51 PMNadeem

Sir,
Thanks for the source..Can you pls advise me how I can use Sys Month, day,year instead of Month,day,year in the check box...I mean it should show July 29 2001 in the boxes.
Thanks.
My email addres..nadeem_qur@yahoo.com
(If this comment was disrespectful, please report it.)

 
7/29/2001 4:50:57 PMNadeem

Sir,
How can I use sys date..in the box field which is July 29 2001 instead of Month date year.
Thanks
(If this comment was disrespectful, please report it.)

 
8/28/2001 11:52:15 PMLim Kian Cheong

I you want to automatically display the system date, modify each portion of the code as below:

in the MonthDropDown function, modify the for loop as below:
If i = Month(Date) Then
strSelectedString =
(If this comment was disrespectful, please report it.)

 
2/7/2002 3:38:08 AMzhuzhu

Hi,
As I can see that there's no specific name for the individual drop down boxes, so how can I change the names & save the date into a database? or there is any other ay that I can do it?

(If this comment was disrespectful, please report it.)

 
1/26/2003 1:27:30 AM

Case 2: if ( (CInt(strYear) Mod 4 = 0 And CInt(strYear) Mod 100 <> 0) Or ( CInt(strYear) Mod 400 = 0) ) Then ... --> you can replace this with Case 2 : If IsDate("February 29, "& strYear) Then strDays = 29 Else strDays =28
(If this comment was disrespectful, please report it.)

 
2/25/2003 4:32:32 AM

Havent tried implementing it, but so far I think its a nice idea something small but common in every asp code .
you saved lots of people time.
(If this comment was disrespectful, please report it.)

 
10/4/2004 9:53:24 PM

i'm very new to all of this.. where should i put this code? can u please guide me on how to use this code.. thanks..
(If this comment was disrespectful, please report it.)

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997-2008 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.