dynamically populating a select box depending upon selections in another select box

Dear sir,

I am trying to populate a select box depending on multiple selections in another select box.

I find the dependent select box does not populate at all.

while it does populate if the parent select box is a single election box and not multiple.

i want to use javascript so that for population i do not have to go to the server.

I am using onchange event to execute the function.

 Some one please help.

pcg

0
pcg
9/5/2008 2:57:27 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

4 Replies
888 Views

Similar Articles

[PageSpeed] 59

Could you post your code?


jameswright
www.jwright.info

"Never be so busy making a living that you forget to make a life."
0
jameswright
9/5/2008 3:59:03 PM

Relevent code is given below please. Page is able to run. But the box2 is not getting populated.

pcg 

 

 

function init()
{

   Gpopulate();

  }

var Gstore = new Array(); 

Gstore[0] = new Array('Select');
Gstore[1] = new Array('Select','Arts and Humanities','Communication','Economics','English','Film','Fine Arts','Hindi','History','Journalism','Maths','Pass Course','Political Science','PR/Advertising','Psychology','Sanskrit','Sociology','Statistics','Vocational Course','other');
Gstore[2] = new Array('Select','Architecture','other');
Gstore[3] = new Array('Select','Management','other'); 

function Gpopulate()

 {

var box = document.forms[0].GCourseName;

 var box2 = document.forms[0].GSpecialization;

var number= 0;

var list=new Array();

 for (j=0;j<box.options.length;j+=1)
 {
    if (!number) return;
    box2.options.length = 0;
    if(box.options[j].selected==true)
    {
       number= j;
       list = Gstore[number];
        for(i=0;i<list.length;i+=1)
        {
        box2.options[i] = new Option(list[i],list[i]);
        }
        }
    }
}

 

<select id="GCourseName" onchange="Gpopulate()" multiple="multiple" runat="server" width="160px">
            <option value="0" selected="selected">Select</option>
            <option value="1">B.A</option>
            <option value="2">B.Arch</option>
 </select>
  <select onselectstart="Gpopulate()" id="GSpecialization" onchange="SpecChange('GSpecialization')" multiple="multiple" runat="server" width="160">
            <option selected="selected">Select</option>
 </select>

 

0
pcg
9/6/2008 4:36:08 AM

Hi pcg,

Please refer the following link to solve your problem, the link will show you how to do it step by step,

http://ralphie.perlmonk.org/mosix/rev_3d1.html

But you need to change the following code, just take the HTML parts,

			$$r->print("<form name='abe'>");
			$$r->print("<center><select name='abe1' onchange='dosel()' size='4'>");
			$$r->print("<option value='1'>Ball</option>");
			$$r->print("<option value='2'>Strike</option>");
			$$r->print("<option value='3'>Batted Foul</option>");
			$$r->print("<option value='4'>Batted Fair</option>");
			$$r->print("</select>");
			$$r->print("<select name='abe2' size='4' style='width:200;'>");
			$$r->print("<option>Subcategory</option>");
			$$r->print("</select></center><br>");

 


Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hong
9/10/2008 9:11:29 AM

Thanks ocean.

This has helped. I am now able to populate the select box2 depending upon the selection in Select box1.

My problem is when I submit the form for processing at server, the population of box2 is not available at all.

I find perhaps view state does not carry the items populated in box2 or their selection to server on submit. Thus the values of box 2 are not available to the function buttonsubmitclick at server to process. I am able to do it in a very round about way of creating some text boxes, filling those with the selected values of the box2 then processing these textboxes values in the buttonsubmitclick function.

Pl suggest the solution.

Thanks in advance.

pcg

0
pcg
9/17/2008 12:15:26 PM
Reply:

Similar Artilces:

Load Text box of one web form with selected list item of list box of another web form
one help please Problem is i have two web forms  1.  ForiegnkeyTest.aspx  2. foroginkeytable.aspx   step 1 1 ForiegnkeyTest.aspx one web form <head runat="server"><script language="javascript" type="text/javascript">   function popWin()   {         var confirmWin = null;      confirmWin = window.open('foroginkeytable.aspx','anycontent',   'width=455,height=435,status');   }  </script> &...

Populate a text box based on dynamic dropdown box selection.
I will try and explain this as best as possible as I am pretty green to asp.net.  I created a data set that pulled in an employee id (primary key), employee name, their department, location, and extension.  I made the employee name a dynamic dropdown list where when the user chose a name, the departmnet, location, and extension boxes would be automatically populated.  I am just not experienced enough to know how to complete this process and I have looked all over the web for an answer, which led me here.  Hopefully there is someone who can help me accomplish my task, or a...

populating items in dropdownlist box based on a selection from another dropdownlist box
I need to populate the respective states from the states dropdownlist when a user chooses a country from the country dropdownlist. Similary when the state is selected from the states dropdownlist the corresponding cities should get displayed in the cities dropdownlistbox. Pls provide me with the coding? Here is the following code which i developed. Code:====Private Sub fillcountry()        ddlcountry.Items.Add("India")        ddlcountry.Items.Add("UK")        ddlcount...

Second SELECT-box doesn't show the selected value as SELECTED
Hi! I usually find what I look for in the other threads, but now I've spent two weeks searching and I still can't work this out, even though I'm sure the solution is easy:( Why doesn't my second dropdown-list show the selected value Arb (which shows in the url-window as for example myPage.asp?Ar=1976&Arb=1987) as selected? It manages to use the Ar-variable for the first SELECT-box, but the second box always has the first querystring-value selected, as if Arb="". I've also tried using a second sql-query, doing exactly as with the first SELECT-box, without success. Is ...

SELECT from SELECT
Hi! I remember seeing an example where you can do a select from a nested select, but I cannot seem to make it work. So it would be something like this: select max( name ) from ( select name from customer union select name from vendor ) Was I dreaming I saw that? Thanks! D In article <4500243f@forums-2-dub>, daniel_AT_infrontsoftware_DOT_com@N0SPAM.com says... > Hi! > > I remember seeing an example where you can do a select from a nested > select, but I cannot seem to make it work. No, you weren't. Try (UNTESTED!) adding a...

reading text in selected select box
i have an html select box and I can read the selected value without a problem. how would i grab the Text? Request.Form["AFFX"].SelectedIndex.Text? Im having a brain fart here.Chopps If it's merely an HTML select and the Select's name is AFFX - - then just use Request.Form("AFFX") if it's an ASP DropDownlist - - use: DDLID.SelectedItem.TExtDavid WierMCP/ASPInsiderASPNet101.com - where to look first!Please Vote for ASPNet101 - 'Best Community Resource'!Control Grouper - easily control properties for multiple controls with one control!Calendar Express ...

how to make one list box(this list box should have selected products) gets filled from another list box (for example this list box has the whole products) by using navigation control
Hello Mate!, I have two list boxes. one should get populated with whole products. and i have another list box in which i have to move some of the products which i like .   The design should be the one below: List Box1   List Box 2 all products   Selected products BMW    >> BMW BENZ     > LEXUS AUDI     <   LEXUS    <<     Could you please suggest me whether i have to use buttons(by which i move items from one list box to another)  ...

Why is the select saying selected after an item is selected?
This was a whitelisting issue due to a software upgrade at hostgator..  Nothing wrong with my code..Scot King SEO Software Tool | Search Engine Optimization"Get your page rank high"  huh? It is smart to put your question in the body and not just in the title. Have no idea what your question is or if it even a question.Eric Pascarello.com | Twitter epascarello | LinkedIn use thisddl.options[ddl.selectedIndex].selected = false; //Clear the selection ddl.options[1].selected = trueMAKMark as Answer if this reply helps youMVP ASP/ASP.NetASP.Net Hosting : Host DepotMy Sit...

Details view with a select box to select the categories
Hello, Thansk to all you that can reply this post.  What I need to do is very simple, I use to do in VB ASP before and now that I'm migrating to .net is not so simple. Here is what I need, I have some categories of products and some subcategories, the cat I select on a dropdownbox and on the details view show all the data on subcat. i have a key of relationship similar to cat. and subcat 1-infinit. Up to this point everything works fine, perhaps when I try to edit/update/insert a message error show: <asp:SqlDataSource ID="SqlDataSource2" runat="server&qu...

Select All/De-Select All Check boxes in Module
I have been looking over the core framework in an effort to find a solution to find a way of making a template column in a custom module select and deselect all check boxes in that column via a single check box at the top or bottom of that collumn like the file manager.  I note the file manager source contains: function gridCheckAll(sender) {      m_bAllFilesChecked=!m_bAllFilesChecked;      CheckAllFiles(m_bAllFilesChecked);      if (!m_bAllFilesChecked)      {      sender.sr...

superreview requested: [Bug 297172] Select box bug when dynamicly enabling and disabling multiple selects. : [Attachment 197270] Proposed patch
Boris Zbarsky <bzbarsky@mit.edu> has asked Peter Van der Beken <peterv@propagandism.org> for superreview: Bug 297172: Select box bug when dynamicly enabling and disabling multiple selects. https://bugzilla.mozilla.org/show_bug.cgi?id=297172 Attachment 197270: Proposed patch https://bugzilla.mozilla.org/attachment.cgi?id=197270&action=edit ...

superreview granted: [Bug 297172] [FIX]Select box bug when dynamicly enabling and disabling multiple selects. : [Attachment 197270] Proposed patch
Peter Van der Beken <peterv@propagandism.org> has granted Boris Zbarsky <bzbarsky@mit.edu>'s request for superreview: Bug 297172: [FIX]Select box bug when dynamicly enabling and disabling multiple selects. https://bugzilla.mozilla.org/show_bug.cgi?id=297172 Attachment 197270: Proposed patch https://bugzilla.mozilla.org/attachment.cgi?id=197270&action=edit ------- Additional Comments from Peter Van der Beken <peterv@propagandism.org> >Index: content/html/content/src/nsHTMLSelectElement.cpp >============================================================...

superreview requested: [Bug 269561] Dropup/dropdown boxes leave gray box visible after selection if <select> has height/width on Mac : [Attachment 170711] Possible patch
Mike Calmus <mcalmus@nyx.net> has asked for superreview: Bug 269561: Dropup/dropdown boxes leave gray box visible after selection if <select> has height/width on Mac https://bugzilla.mozilla.org/show_bug.cgi?id=269561 Attachment 170711: Possible patch https://bugzilla.mozilla.org/attachment.cgi?id=170711&action=edit ------- Additional Comments from Mike Calmus <mcalmus@nyx.net> This patch is somewhat inelligant, but it seems to work. ...

select boxes
Name: Chris Product: Firefox Summary: select boxes - background-color is not shown on selected option Comments: I am a web developer and noticed that firefox and netscape browsers do not show the background color defined in the style sheet or explicit style attribute for a selected option Code Example: <option style="background-color:#cccccc;">Option 1</option> If this option were selected it would not show the grey background color. Instead it is default white. The background-color is only shown when viewing the expanded drop menu. As a developer...

Web resources about - dynamically populating a select box depending upon selections in another select box - asp.net.web-forms

Placebase team at Apple file “Schematic Maps” patent dynamically detailing important data
In a report from Computerworld way back in 2009, we learned that Apple had quietly acquired Maps API company Placebase. Then, founder of Placebase ...

Apple's Lightning port dynamically assigns pins to allow for reversible use
... a closer look at how Apple's new Lightning connector works, and has come to the conclusion that the 8 pins on each side of the plug are dynamically ...

In a dynamically typed language, is it a bad idea to return different data types?
In some cases, returning different types from a single function works.

Urlbox Launches Screenshots-as-a-Service Platform to Dynamically Update Galleries
... changes. Launched yesterday, Urlbox allows anyone with a gallery displaying website screenshots to automate the process and keep them dynamically ...

Everything.me launcher dynamically adapts to what you’re doing right now
... phone according to what you’re doing. Perform a search for ‘football’ and your background will change to the NFL logo. A launcher that dynamically ...


A YouTube Experiment Resizes the Player Dynamically
There's a new YouTube experiment that changes the video player's size, depending on the browser window's size. When resizing Chrome's window, ...

Apple Granted “Dynamically Changing Cursor for User Interface” Patent, Originally Filed in 2003
... a utility patent that covers the use of the mouse cursor that changes according to the context of the task it is engaged in. Called a “Dynamically ...

Atmel's FPSLIC II Dynamically Reconfigurable SoC Supports "Silicon-Sharing" For Peripherals & Interfaces ...
Silicon-Sharing Fits 200K Gate Design into 40K Gate FPSLIC II's, Cuts Power Drain by 97%

Everything.me Launcher Wants to Dynamically Change Phones Based on Location, Interests, and Mental State ...
What if your phone’s launcher dynamically changed based upon interests, your location, or topics you had in mind at a specific moment? A new ...

Resources last updated: 12/3/2015 9:20:59 PM