Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

output data based upon choice of a select menu

Posted on 2003-03-20
11
Medium Priority
?
162 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
  • 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
Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

 
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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

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

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…
Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

564 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