Solved

dynamic dropdown boxes

Posted on 2004-03-30
5
993 Views
Last Modified: 2013-12-24
I hope that somebody can help

I have taken some code from the solution of http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_10968981.html and have modified it to fit in with my tables.

Given my non-existent knowledge of java, I am very proud to have gotten to my current position. I am able to correctly populate the first drop-down but have fell fowl in the sub-option section.  

My tables are

lut_jcu_degrees with field degree as the primary key (varchar2)

lut_discipline_degree with field id as the primary key (number); the field degree is the foreign key (varchar2)

I suspect that my problem could well lie with the fact that the pk/fk are varchar2 - unfortunately I am not in the position to change this as this is information comes to me from an external source.

I am hoping that somebody can help me to re-modify the code so that when an option is selected in the first box, only those corresponding options are displayed through the second drop-down.  

Also, I am not sure how I go about actually having the values that do get selected submitted... I can get to this later though, my first priority is to get the two list correlating.

Any help is greatly appreciated.

My code follows

<!--- query the database to retrieve the degrees for the first select control --->
<CFQUERY NAME="qrydegree" DATASOURCE="corpdb" DBTYPE="ODBC">
SELECT      degree, description
FROM         lut_jcu_degrees
ORDER BY  description
</CFQUERY>

<!--- query the database to retrieve the disciplines for the first select control --->
<CFQUERY NAME="qrydisdeg" DATASOURCE="corpdb" DBTYPE="ODBC">
SELECT      id, discipline, degree
FROM         lut_discipline_degree
ORDER BY  discipline
</CFQUERY>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
     
<HTML>
<HEAD>
     <TITLE>Dynamic Select Box Updates from Cold Fusion</TITLE>
</HEAD>

<!--- serialize the qrytype result set into WDDX --->
<CFWDDX ACTION="CFML2JS"
        INPUT="#qrydegree#"
        TOPLEVELVARIABLE="jsdegreeTLV"
        OUTPUT="jsdegree">

<!--- serialize the qryclass result set into WDDX --->
<CFWDDX ACTION="CFML2JS"
        INPUT="#qrydisdeg#"
        TOPLEVELVARIABLE="jsdisdegTLV"
        OUTPUT="jsdisdeg">

<!--- get the WDDX JavaScript utility object --->
<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript" SRC="../CFIDE/scripts/wddx.js">
</SCRIPT>

<!--- start the script to dynamically create the dropdown list --->
<SCRIPT LANGUAGE="JavaScript">

<!--- output the type WDDX packet --->
<CFOUTPUT>#jsdegree#</CFOUTPUT>

<!--- output the class WDDX packet --->
<CFOUTPUT>#jsdisdeg#</CFOUTPUT>

<!--- create a function that runs when the user selects from the first dropdown list --->
function choosenext()
{
     <!--- if 'Choose One' is chosen from the first dropdown list populate the second dropdown list with just a blank option --->
     if (document.TestForm.Select1.selectedIndex==0)
     {
          document.TestForm.DynamicSelect.options.length=0;
          NewOpt=new Option;
          document.TestForm.DynamicSelect.options[0]=NewOpt;
     }

     <!--- Update second box --->
     else
     {
          document.TestForm.DynamicSelect.options.length=0;
          var BoxNum = 0;
          for (var RowNum=0; RowNum<jsdisdegTLV.id.length; RowNum++)
          {
               if (jsdisdegTLV.degree[RowNum] == document.TestForm.Select1.selectedIndex)
               {
                    NewOpt=new Option;
                    NewOpt.value=jcdisdegTLV.id[RowNum];
                    NewOpt.text=jcdisdegTLV.discipline[RowNum];
                    document.TestForm.DynamicSelect.options[BoxNum]=NewOpt;
                    BoxNum++;
               }
          }
     }
document.TestForm.DynamicSelect.options[0].selected = true;    
}
</SCRIPT>

<BODY>

<!--- the actual form --->
<FORM ACTION="test_action.cfm" METHOD="POST" NAME="TestForm">

Select an option:
<select name="Select1" onChange="choosenext();">
     <OPTION VALUE="0">Choose One</OPTION>
     <cfoutput query="qrydegree">
          <OPTION VALUE=#degree#>#description#</OPTION>
     </cfoutput>
</SELECT>&nbsp;&nbsp;
Sub-option:
<SELECT NAME="DynamicSelect">
     <OPTION VALUE="0">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</OPTION>
</SELECT>
<BR><BR>

<INPUT TYPE="Submit">
</FORM>

</BODY>
</HTML>
0
Comment
Question by:jainesteer
5 Comments
 
LVL 11

Accepted Solution

by:
hart earned 250 total points
ID: 10721702
go to this link and u will get a ready made cf tag which takes care of 2 dynamic dropdowns

http://www.macromedia.com/cfusion/exchange/index.cfm?view=sn131&extID=1000288

Regards
Hart
0
 

Author Comment

by:jainesteer
ID: 10730002
Thanks for that - I do appear to be getting slightly better at this whole CF/Java thing even though I have absolutely no idea about what I am doing.

I have mastered the whole two related drop down thing for a SINGLE entry, but now would like to give users a first and second preference option.  I have included the code to date, and all works except that I can only ever get the last row of data to have entries in both columns.  I would REALLY appreciate somebody taking a quick look at the code that I have so far - I know that I have to loop but where to go next is a big mystery.


<CFQUERY NAME="qrydisdeg" DATASOURCE="corpdb" DBTYPE="ODBC">
SELECT LUT_DISCIPLINE_DEGREE.ID, LUT_DISCIPLINE_DEGREE.DISCIPLINE, LUT_JCU_DISCIPLINES.DESCRIPTION AS Discipline_name, LUT_DISCIPLINE_DEGREE.DEGREE, LUT_JCU_DEGREES.DESCRIPTION AS Degree_name
FROM (LUT_DISCIPLINE_DEGREE INNER JOIN LUT_JCU_DEGREES ON LUT_DISCIPLINE_DEGREE.DEGREE = LUT_JCU_DEGREES.DEGREE) INNER JOIN LUT_JCU_DISCIPLINES ON LUT_DISCIPLINE_DEGREE.DISCIPLINE = LUT_JCU_DISCIPLINES.DISCIPLINE;

</CFQUERY>
<table width="800" cellspacing="5" cellpadding="1" border="2" >


<cfloop from="1" to="1" index="x">
<tr>
 <CF_TwoSelectsRelated
      QUERY="qrydisdeg"
      NAME1="webtitle#x#"
      NAME2="Discipline#x#"
      DISPLAY1="Degree_name"
      DISPLAY2="Discipline_name"
      VALUE1="Degree"
      VALUE2="Discipline"
      FORCEWIDTH1="70"
      FORCEWIDTH2="70"
      SIZE1="1"
      SIZE2="1"
      AUTOSELECTFIRST="Yes"
      EMPTYTEXT1="(choose a course of study)"
      EMPTYTEXT2="(now choose a discipline)"
      ONCHANGE="updateTable('#x#')"
      FORMNAME="App">
  </cfloop>
      
</table>
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10981812
It sounds like Hart answered your original question since he provided the link that you have used for 2related selects.  SO really he should get the points and then you should post a new question for other issues.  But, please be clear on what exactly you new issue is because I am a little confused by what you are trying to do.

You have a loop around the CF_TwoSelectsRelated tag.

But your loop goes from 1 to 1 which means it only runs once - so why even have the loop?
0

Featured Post

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question