Solved

dynamic dropdown boxes

Posted on 2004-03-30
5
985 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now