?
Solved

output data based upon choice of a select menu

Posted on 2003-03-20
11
Medium Priority
?
161 Views
Last Modified: 2013-12-24
i have three columns in a table one of which is displayed in a select menu. is there a way in CF to cfoutput (display only) the corresponding data from another column based upon the selection that the user makes?
0
Comment
Question by:goldiebugs
[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
  • 6
  • 4
11 Comments
 
LVL 14

Expert Comment

by:Renante Entera
ID: 8178407
Actually it's just a combination of a javascript code and html tags.

Please take this example.

<script language="JavaScript">
function putVal(){
for (i=0;i<document.theForm.nSelect.length;i++){
     if (document.theForm.nSelect[i].selected==true){
     var nCode = document.theForm.nSelect[i].value;
     document.theForm.selected_list.value=nCode;

     }
}
}
</script>

<form name="theForm" action="" method="post">
<table width="40%" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td width="30%">
     <select name="nSelect" size="1" onChange="putVal();">
        <option value="list1">list1</option>
        <option value="list2">list2</option>
        <option value="list3">list3</option>
          <option value="list4">list4</option>
          <option value="list5">list5</option>
    </select>
     </td>
    <td width="30%"><input type="text" name="selected_list" value='list1'></td>
    <td>&nbsp;</td>
  </tr>
</table>
</form>

I hope this could help you a lot.
GOODLUCK.
0
 
LVL 6

Expert Comment

by:dash420
ID: 8178835
<head>
<script language="JavaScript">
function fnChange(){
  document.frmtest.hdnSelVal.value = document.frmtest.lstSelect.options[document.lstSelect.selectedIndex].text
   
 document.frmtest.method = "post"
 document.frmtest.action ="<samepage>
 document.frmtest.submit()
}
</script>
</head>



<cfoutput>
<cfparam name="mySelVal" default="">
<cfif isDefined("form.hdnSelVal")>
   <cfset mySelVal = form.hdnSelVal>
</cfif>

<form name="frmtest" method="post">
<input type="hidden" name="hdnSelVal" value="">
<table cellspacing="0" cellpadding="0">
 <tr>
   <td>
    <select name="lstSelect" onChange="fnChange();">
       <option value="1">list1</option>
       <option value="2">list2</option>
       <option value="3">list3</option>
       <option value="4">list4</option>
    </select>
    </td>
   <td><input type="text" name="txtshow" value="#mySelVal#"></td>
   <td>&nbsp;</td>
 </tr>
</table>
</form>
<cfoutput>
0
 

Author Comment

by:goldiebugs
ID: 8182570
but both of these examples are for hard coded select tags, right? how can i do this using a query to output the data in the select tag?

<select name="pkg_id" class="selectmenu">
<option value="Select a Package" selected>Select Package</option>
<cfoutput query="getpkg">
<option value="#pkg_id#">#num#  - #num_months# </option>
</cfoutput>
</select>
0
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.

 
LVL 14

Expert Comment

by:Renante Entera
ID: 8222120
Since, you want to involve database manipulation.

You can have this example:

<cfquery name="Query_Name" datasource="Database_Name">
select Field_Name from Table_Name
</cfquery>

<!-- set default value to be displayed in any of the three columns of your table -->
<cfparam name="selectedData" default="First_data_in_the_table_of_the_database">

<select name="event" onchange="document.location = options[selectedIndex].value">
  <cfoutput query="Query_Name">
     <option value="disp_selected.cfm?selectedData=#Query_Name.Field_Name#" #IIF(selectedData EQ "#Query_Name.Field_Name#",DE('selected'),DE(''))#>#Query_Name.Field_Name#</option>
  </cfoutput>
</select><br><br>
<table width="50%" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td width="30%">&nbsp;<cfoutput>#selectedData#</cfoutput></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

Then save this as disp_selected.cfm.

Try to run this one.

GOODLUCK!

!!!entrance2002!!!
0
 

Author Comment

by:goldiebugs
ID: 8226398
ok i understand most of this, but i'm confused about one thing. you say to save the above as disp_selected, but then how do i call this page in the original page?
0
 
LVL 14

Expert Comment

by:Renante Entera
ID: 8228910
Upon running this page you just type/call the file name(disp_selected.cfm).

So, the output will goes this way:

1. You have a drop down menu with a default value of the first data being stored in the table of your database with the specified fieldname.

2. The default display on your first column of the three columns of your table will be the parameter being set as selectedData in the code:
<cfparam name="selectedData" default="...">

3. When you select a value from the drop down menu, it will refresh your page then the selectedData will be passed unto the url.

Just try running this one. And if you have any problem don't hesistate to ask me... OK.

Best wishes!
0
 
LVL 14

Expert Comment

by:Renante Entera
ID: 8228923
Additional information:

It doesn't mean that you should have to save the said code as disp_selected.cfm. You can have any as long as it matches to the filename you are calling in the code:

<option value="disp_selected.cfm?selectedData=#Query_Name.Field_Name#" #IIF(selectedData EQ "#Query_Name.Field_Name#",DE('selected'),DE(''))#>#Query_Name.Field_Name#</option>

So, disp_selected.cfm is the filename in my example. If you change this for example: saving this as sample.cfm.

This should be the code:

<option value="sample.cfm?selectedData=#Query_Name.Field_Name#" #IIF(selectedData EQ "#Query_Name.Field_Name#",DE('selected'),DE(''))#>#Query_Name.Field_Name#</option>

Now, is it clear to you?

0
 

Author Comment

by:goldiebugs
ID: 8241186
oi! i think i understand (or at least i'm working on it!), but....is there a way to do this without leaving the page? the reason i ask this is because this form element is one of the first things that is filled out, but there are quite a few more form elements to fill out after this item. whatabout a cfinclude? and if so? how could you do that?
0
 
LVL 14

Accepted Solution

by:
Renante Entera earned 200 total points
ID: 8242626
Perhaps, I have answered your question correctly. So, am I deserving to earn my points with this question?

With regards to your question about cfinclude, just post it as another question with complete specification 'coz I didn't understand it well...Hope you won't mind.

Is it OK for you to do that? So, others may share their ideas regarding your latest question.

Waiting for your favorable response...
0
 

Author Comment

by:goldiebugs
ID: 8246745
you got it! you do deserve the points. i will post the question about how to keep everything on the same page. thank you for all your help!
0
 
LVL 14

Expert Comment

by:Renante Entera
ID: 8250081
Thanks for the points.

And I'll just have to update myself regarding your incoming questions...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 23 hours left to enroll

752 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