ASP Junction Home Of EZCodes
5 visitors online
134125 total visitors

Tuesday, 9 February, 2010
Home Downloads Articles Programming Portfolio Support Privacy  




Newsletter


The HTMLJunction Store

Top 5 Downloads
EZNewsletter: 11039
EZGallery: 6219
EZPoll: 6073
EZUpload: 5503
EZGuestbook: 4255
Download Stats
EZHomepagePro: 3485
EZHomepageBasic: 1573
EZNewsletter: 11039
EZOnlineEditor: 3860
EZMedia: 3596
EZGuestbook: 4255
EZGallery: 6219
EZPoll: 6073
EZScheduler: 2205
EZUpload: 5503
Total: 48396
HTMLJunction News
ASP Article - Dynamic Date Dropdown Menu.

ASP Article - Import Text File to an Access Database.

EZScheduler now available for download!

ASP Junction has just been launched!

HTMLJunction has a new store!


Advertisements






HTMLJunction is against any kind of spyware!




ASP Article
Rated out of 5 stars - 4 Total Votes Submit Your ASP Article


Dynamically populate a Day dropdown menu dependent on the Month selected.



This article will explain how to Dynamically populate a dropdown menu of days dependent on the Month selected.
NOTE: The only caveat is that it does not take Leap Year into consideration!

We will be using Javascript and ASP in this article.

About the Author

Steve Frazier has been a classic ASP developer for about four years. He has developed ASP applications for Fortune 500 companies and popular websites. He has also developed many ASP Scripts of his own! He is Webmaster of HTMLJunction as well as its sister sites. The HTMLJunction Store - ASP Junction. He is currentlly working on a Web Portal that has the functionalities of all the most popular Forums and Portals.

First the Javascript

Place this inbetween the head tags of your document


<script language="javascript">
function focusarea(intMonthID,intNum) {
  this.Num = intNum;
  this.monthID = intMonthID;
}
function getFocusArea() {
  var sSelect = '<select name="dcount">';
  var selectID = document.schedule.mcount.value;
  for (var x=1; x<aFocusArea.length; x++) {
    if (aFocusArea[x].monthID == selectID) {
      for (var i=1; i<aFocusArea[x].Num+1; i++) {
      sSelect = sSelect + '<option>' + [i] + '</option>'
    }
  }
}
sSelect = sSelect + '</select>';
document.all['Focus'].innerHTML = "";
document.all['Focus'].innerHTML = sSelect;
}
var aFocusArea = new Array;
aFocusArea[1] = new focusarea(1,31);
aFocusArea[2] = new focusarea(2,29);
aFocusArea[3] = new focusarea(3,31);
aFocusArea[4] = new focusarea(4,30);
aFocusArea[5] = new focusarea(5,31);
aFocusArea[6] = new focusarea(6,30);
aFocusArea[7] = new focusarea(7,31);
aFocusArea[8] = new focusarea(8,31);
aFocusArea[9] = new focusarea(9,30);
aFocusArea[10] = new focusarea(10,31);
aFocusArea[11] = new focusarea(11,30);
aFocusArea[12] = new focusarea(12,31);
</script>


Just a few notes on the Javascript!


var selectID = document.schedule.mcount.value;

This takes the value from the Month dropdown menu.



  for (var x=1; x<aFocusArea.length; x++) {
    if (aFocusArea[x].monthID == selectID) {
      for (var i=1; i<aFocusArea[x].Num+1; i++) {
      sSelect = sSelect + '<option>' + [i] + '</option>'
    }
  }
}

This part of the function compares the value from the month menu and finds the appropriate array to get the proper day count then populates the day menu with the corresponding number of days.

Place the code below in a place where you can access it, If you are only going to use it on one page then you can put it at the top of your ASP page. If you want multiple pages to access it then what I do is put it in a page called "common.asp" then I use an include at the top of each page I want to use it in IE:
<!-- #include file="common.asp"-->

<%
Sub selectDate
  Response.Write "<select name=""mcount"" OnChange=""getFocusArea();"">" & vbcrlf
  Response.Write "<option value=""0"">Select Month</option>" & vbcrlf
  For mcount = 1 to 12
    Response.Write " <option value="""&mcount&""">" & mcount & "</option>" & vbcrlf
  Next
  Response.Write " </select>" & vbcrlf
%>
<span id="Focus">
    <select name="dcount">
      <option>Select Day</option>
    </select>
</span>
<%
  Response.Write "  <select name=""ycount"">" & vbcrlf
  For ycount = 7 to 20
    If ycount >= 10 Then
      Response.Write " <option>20" & ycount & "</option>" & vbcrlf
    Else
      Response.Write " <option>200" & ycount & "</option>" & vbcrlf
    End If
  Next
  Response.Write " </select>" & vbcrlf
End Sub
%>


To use the Sub Procedure above place the form below where you want the menu to appear on your ASP page:

<form action="myform.asp" name="schedule" method="post">
<% selectDate %>
<input type="submit" value="Submit" />
</form>

Or you can place it inbetween your ASP code:
<%
Response.Write "<form action="myform.asp" name="schedule" method="post" >
Some ASP form code...

selectDate

Some more ASP form Code
</form>
%>

Note that the name of the Form is "schedule" that MUST be included in the form tag.

Try it out!

Well thats all there is to it! I hope you find this article useful!

Rate this Article
Good  
5 4 3 2 1
  Poor

Advertisements








We use Google Sitemaps to inform Google's crawler about all your pages and to help people discover more of your web pages.

Advertisements






Resources

Gunners Gallery
Wesley Ford
seo-advantage.com

copyright © 2010 ASP Junction
An HTMLJunction website