?
Solved

dynamic dropdown boxes

Posted on 2004-03-30
5
Medium Priority
?
1,004 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 11

Accepted Solution

by:
hart earned 1000 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

Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

Question has a verified solution.

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

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

762 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