How to make two dropdown boxes links together?

Results 1 to 3 of 3

Thread: How to make two dropdown boxes links together?

  1. #1
    Join Date
    Dec 1969

    Default How to make two dropdown boxes links together?

    Hi all,<BR><BR>I want to write an ASP page which contains 2 dropdown boxes that are linked together. The problem is the second one doesn&#039t correspond to the first one.<BR><BR>Following is my code. Any help would appreciated. <BR><BR>&#060;script language=vbscript&#062;<BR> Sub cboSectorID_OnClick()<BR> &#060;!-- #include file="" --&#062;<BR>&#060;%<BR> &#039Check for database errors<BR> Call CheckForErrors(objConn)<BR><BR> &#039Create the recordset object and open the recordset<BR> Set objRS = Server.CreateObject("ADODB.Recordset")<BR> objRS.Open "Select SkillID from tSkill where Sector_ID = &#039"& _<BR> Request.Form("cboSectorID") & "&#039", "dsn="Test"<BR> <BR> &#039Check for database errors<BR> Call CheckForErrors(objConn)<BR>%&#062; <BR><BR> &#039Clear the contents of the combo box<BR> For i=0 to i&#060;document.all.cboSkillID.length<BR> document.all.cboSkillID.remove(0)<BR> Next<BR><BR>&#060;%<BR> &#039add each skill to the combo box<BR> Do While Not objRS.EOF<BR>%&#062;<BR> Set objOption = document.createElement("OPTION")<BR> objOption.text = "&#060;%=objRS("SkillID")%&#062;"<BR> objOption.value = "&#060;%=objRS("SkillID")%&#062;"<BR> document.all.cboSkillID.add objOption<BR>&#060;% <BR> objRS.MoveNext<BR> Loop<BR>%&#062;<BR> &#060;!-- #include file="" --&#062;<BR> Set objOption = Nothing<BR> End Sub<BR><BR>Thanks,<BR>June

  2. #2
    Join Date
    Dec 1969

    Default RE: How to make two dropdown boxes links together?

    Are you trying to make it so that when one user clicks an item in the first box, the values in the second dropdown box change dynamically (i.e, you have parent values in the first one and child values appear in the second one based on the pick from the parent one)? I have been looking for something to do this while dynamically calling the data from the database as it does so. Was wondering if this is also what you are trying to do?

  3. #3
    Join Date
    Dec 1969

    Default Two primary ways...

    (1) Put all the data on the page via the first query and use client-side scripting to fill the second drop-down with the appropriate set of data when one item in the first is clicked on.<BR><BR>(2) Put up just the first set of data. When the user clicks on an item in that first set, you make a round-trip to the server and get a new page that has the data in the second list filled in.<BR><BR>**************<BR><BR>Solution (1) *can* have performance advantages, esp. on crowded (thousands of hits per hour) sites. All the data is on the browser side and even when the user changes his/her mind, no further hit on the server is needed. This is, however, generally a complicated solution and, if you want to be browser independent, involves understanding JavaScript in the browser pretty darned well. If you want to go this route, go to and search for "dynamic lists" should find several pages on the topic.<BR><BR>Solution (2) is pretty simple and can be done essentially all in ASP code. Except... (there is *always* an except, isn&#039t there?) Except that if the user has already entered any *other* form info on the page, that info will be lost unless you copy it to the newly generated page. Fortunately, for most form field types this is pretty easy. Note that every time the user makes a different selection from the first list, this technique will require a round trip to the server. No problem on sites that get no more than a few hundred hits per hour. Perhaps something to be thought about on *really* crowded sites. Anyway, if you want to see this solution, I have an example at under the demo title "Multiple drop down lists".<BR><BR>One of these days, I&#039m going to get around to putting up the same page using both techniques, just for comparison. But for now, you&#039ll have to look at the two very disparate sites.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts