.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Need help to populate dropdownlist using Javascript

Posted By:      Posted Date: October 07, 2010    Points: 0   Category :ASP.Net

Hi, I'm doing a simple HTML form, that requires two dropdownlist - one that populates the month, and the other to populate the dates based on the month. For example, in January, there are 31 days. So the "date" dropdownlist will populate 1-31 in the "month" dropdownlist. The "date" dropdownlist will change to 1-28 for February when selected and so on...  Can someone please help me with the javascript section? I'm coding using javascript.

Many Thanks!


<title>Test Form</title>
<script language="JavaScript">
function testDate(){

var MonthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var count = 0;
 if(location.href = document.form1.month.options[document.form1.month.selectedIndex].value) {
  for(var i=1; i<=(MonthDays[count]); i++) {
   document.writeln('<option value="'+i+'">' + i + '</option>');



<form id="form1" name="form1" method="GET">
  <label>Post Reminder:<br />
  <input type="text" width

View Complete Post

More Related Resource Links

dropdownlist javascript change items


I can't find solution for this problem for very long time:

I have dropdownlists in Gridview. I need to dinamicly change content of dropdown on client with javascript. Ok, I know to do that. But the problem is when I send data to server changes in dropdownlist does not see. On server I have  old items. How can I change items in dropdown on client with javascript and than see that items on sever when postback data?


How to use parameter from Dropdownlist to populate Rep. Table

I successfully have populated a dropdownlist from a database. Now I need to create a sort of a Master/Detail situation - based on the selection in the DropDownlist, I need to populate a Repeating table. I just can't find any examples or tutorials on how to do this. I've tried stuff till my fingers were bleeding. Can someone help me figure this scenario out, please?

Validating DropdownList Inside Gridview Using Javascript

hi All,      I have Gridview with Dropdownlist which contains data as {select,1,2,3} .Gridview contains multiple rows of data.Submit button is also on form but outside gridview. If any of the rows of gridview dropdownlist contain value as "Select" and click Submit button ,give message as "Please select value". I want to do this stuff using javascript. Thanks in advance.

Get the Dropdownlist text and value using Javascript from client side

Hi, I am encountering a problem about how to get the Dropdownlist text and value using Javascript from client side. I am using C# in Visual Studio 2005 and Javasript . The example codes are like: ( In this example code, I would like to access the text and value of the DropDownListReports in the run() function of Javascript. How can I do that? Any ideas? Thanks a lot. ) protected void Page_Load(object sender, EventArgs e) {              if (!Page.IsPostBack)               {                     DropDownListReports.Items.Clear();                     ListItem listItem = new ListItem();                     listItem.Text = "aText";                     listItem.Value = "aValue;                     DropDownListReports.Items.Add(listItem);         &nbs

DropdownList Selection to Populate TextBox

I have a dynamically generated dropdownlist, that lists e.g. Company Names. I want to be able to select a particular Company and display associated information e.g. Name, Address, City, State... etc. in text boxes adjacent to the list. I am trying to fire the following code from the dropdownlist "OnSelectedIndexChanged" property, but cannot 1) get the code to fire upon selection, and 2) populate the text boxes... any suggestions are appreciated!! Thanks CODE:     Public Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Facility.SelectedIndexChanged Dim FacilityAddressDetail As String  Dim FacilityAddress2 As String  Dim FacilityCity As String  Dim FacilityState As String  Dim FacilityZip As String Dim   FacilityAddressDetail = FacilityAddress2 = FacilityCity = FacilityState = FacilityZip =       mySettingsSIC = AppSettings   dgiSelectedIndexChange As DataGridItemFor Each dgiSelectedIndexChange In myDataGrid.ItemsCType(dgiSelectedIndexChange.FindControl("FacilityAddressDetail"), TextBox).TextCType(dgiSelectedIndexChange.FindControl("FacilityAddress2"), TextBox).TextCType(dgiSelectedIndexChange.FindControl("FacilityCity"), TextBox).TextCType(dgiSelectedIndexChange.FindControl("FacilityState"), TextBox).TextCType(dgiSelec

DataList/FormView won't populate DropdownList

I have a ddl inside the formview that I can't figure out how to wire up properly. The formview contains detail info, but the ddl needs to list the entire set to items. Then I want the ddl's selected value be set from the recordset intended  for the formview. I think it's just a timeing issue s I would like your help. Thanks, - EJM. Here my code somewhat reduced to save space...<asp:DataList Width="700" ID="DlMembers" runat="server" DataKeyField="Ident" OnItemCommand="DlMembers_ItemCommand" OnDeleteCommand="DlMembers_DeleteCommand" > <HeaderTemplate> <table border="1" cellpadding="2" cellspacing="0"> <tr align="left" valign="top"> <th nowrap>First Name</th><th nowrap>Last Name</th><th nowrap>Address</th><th nowrap>Email</th><th nowrap>Home Phone</th><th nowrap>Work Phone</th><th nowrap>Cell Phone</th><th nowrap>Position</th><th nowrap>Admin</th><th nowrap>Comments</th><th> </th><th> </th></tr></HeaderTemplate><ItemTemplate>

Populate DropDownList in InsertItemTemplate after insert

I thought this one would be easy, but no go. What I am trying to do is the following: I have two DropDownLists in my InsertItemTemplate, each bound to its own datasource. After the fields in this form have been filled out and the ItemInserting event fires, I rebind the ListView to its datasource, but the DropDownLists turn out empty. I tried to bind them in the ItemInserting event and it seems they get filled, but nothing shows up in them when the page loads. I also tried to fill them in the ItemDataBound event, but the e.Item.ItemType == InsertItem doesn't do it. What is the solution?

Populate dropdownlist in Edit mode programatically


I'm trying to programatically populate some dropdownlists inside a formview in EDIT mode, like this below.

 Dim FVM As String = FormViewMemberProfile.CurrentMode.ToString

        If FVM = "Edit" Then

            Dim ddlDays As DropDownList = CType(FormViewMemberProfile.FindControl("ddlDays"), DropDownList)
            Dim ddlYears As DropDownList = CType(FormViewMemberProfile.FindControl("ddlYears"), DropDownList)

            Dim i As Integer = 1

            For i = 1 To 31

            Dim k As Integer

            For k = 1930 To 2008

        End If

I orginally had this running as part of the pagelaod event, but I'm thinking that b/c the page loads first, it doesn't populate the fields in EDIT mode until after the data is saved, and then page is reloaded. Now it knows it's in "Edit" mode. Am I thinking clearly here? Not sure if this is the order of things... Anyhow...

So I thought I should just use a formview_modechanged (or similar event) so when the user switches modes, it populates the fields - but I'm not sure which event I should use. I've tried "Modechanging", "modechanged", "prer

AJAX DropDownList won't populate.. error500.. code is working though.


Here's what I have.  I was able to debug and traverse through the webservice and return teh array back into the first call method of: return new CarsService()..  But back in the page_load method, I can't get it to update and show up in the page.  what am I doing wrong?!?!


<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                    <cc1:CascadingDropDown ID="CascadingDropDown1" runat="server" TargetControlID="DropDownList1"
                     Category="Make" PromptText="Please select a make" LoadingText="[Loading makes...]"  

Items added through Javascript to a dropdownlist are not accessible through code behind


Hi All,

I am successfully able to add new items to a drop down list using Javascript.

The script I am using is 

        function FillJavaScriptValues() {
            var ddlDeliveryVan;
            ddlDeliveryVan = document.getElementById("DropDownList1");
            var opt = document.createElement("option");

Disable DropDownList using Javascript


I need to diable a DropDownList when a CheckedBox is checked.Both the controls are on Content Page. How can I achieve this using Javascript? 

Any help would be appreciated!!

How to dynamically populate a ComboBox through client-side Javascript?


I'm using the ComboBox control from the May 2009 release of the ASP.NET Ajax Control Toolkit.

I'd like to try and populate this ComboBox's list of options dynamically from the client-side Javascript (because I'm retrieving the data from the server based on the user's selection in another drop-down box).  Can anyone suggest how to accomplish this?  I tried this:


                var teacherComboBox = document.getElementById("ctl00_ContentPlaceHolder1_TeacherComboBox_OptionList");
                teacherComboBox.innerHTML = "";
                for (var i = 0 ; i < result.length ; i++) {
                    var listitem = document.createElement("li");
                    listitem.innerHTML = result[i];


And it didn't work.  The ComboBox just ended up with just one item (the first one) in the list, instead of all of them.

Any help appreciated.


Dynaimicaly create dropdownlist - Javascript


Hi to all,

I have a web page default.aspx while loading this page i create dropdownlist dynamicaly by using Javascript, my doubt is now i want to write some java script code during the dropdownlist selected Index changed event, how to write it, this is possible if we design the controls at design time but i create it by runtime so anybody tell me how to write the event of the dropdownlist.?

Thanks in advance.

Cannot populate the textbox with selection from dropdownlist. Thanks

I am not able to get the selection from dropdown into the detailsview template field during update. 

 <asp:TemplateField HeaderText="SupplierName" SortExpression="SupplierName">
                  <asp:TextBox ID="TextBox1Sup" runat="server"  Text='<%# Bind("SupplierName") %>'  Visible="True"></asp:TextBox>
                  <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true" 
                  DataSourceID="AccessDataSource" DataTextField="CompanyName" 
                     DataValueField="CompanyName" AutoPostBack="True"  
                        > </asp:DropDownList>                    
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("SupplierName") %>'></asp:TextBox>
                        <asp:Label ID="Label2" runat="server" Text='<%# Bind("SupplierName") %>'>&

Help: populate Html.DropDownList from table data? [Linq to SQL model]


I have two tables, Users and Roles.  The roles table is a reference table for the different roles of my site (RoleId and RoleName columns). The Users table contains profile data for each user, including a RoleId column that is FK'd back to the Roles table [RoleId].

Both tables are in a Linq to SQL model.

I have an edit page created which lists all the profile values of a user.  The edit page inherits the User model.  One of the editable values is the RoleId field.  I want to set this up to be a drop-down list that contains items labeled using the RoleName column of the Roles table, and matched with values of RoleId.

How can I achieve this?

populate label/textbox from dropdownlist in insert item template


I've been trying to find a solution to my problem for about 2 days now, and have found nothing.  I am new to .net and not really sure how to accomplish this. 

I have 4 tables in a database, Vendors, RepairCos, Cons, ConRepairHistory.   What I'm trying to do is make a page called SendOutForRepair.aspx that has a insert item template where the first control is a dropdownlist that is attached to the Cons table (got this figured out) and is populated with the Serial Number field.  I would like the selection from the dropdownlist to populate the 2nd control (VendorID) that is also from the Cons table.

example record from Cons Table:  Serial number      VendorID
                                                      508585                     1

so when 508585 is selected in the dropdownlist, it would populate VendorID with 1 (this is my issue)

once this happens, the user would fill in the other fields (hours, issue, repairco (al

Populate a dataGridview based on select an item in dropdownlist!


Hello all!

In window form,  there are two comboBoxs named cbo1, cbo2 with populate the same items in the dropdownlist as following: For examples,

Class A

Class B

Class C

I like to populate the data into two dataGridViews named dgv1, dgv2 based on selecting an item in two dropdownlists. The rules is if I select an item in the cbo1 to populate data in dgv1, and cbo2 with hide (remove) an selected item from cbo2 to avoid that the user selects the same item for populate the same data in the dgv2. In a brief, the displayed data in two dgv1, dgv2 are different. Any helps in C# code, I really appreciate it. Thanks in advance.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend