| | |
how to populate a cfselect box depending upon the selection on raido button
Please support our ColdFusion advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2009
Posts: 7
Reputation:
Solved Threads: 0
Hi
I am new to coldfusion.I dont know much about
cold fusion.I have a problem like there are two radio
buttons and a select box.Depending upon the slection of
the radio button the select box should be populated.i.e
if first radio button is selected then select box should
populate some set of values and if second radio button is
slected then selct box should be populated with other set
of values
Thanks in Advance
I am new to coldfusion.I dont know much about
cold fusion.I have a problem like there are two radio
buttons and a select box.Depending upon the slection of
the radio button the select box should be populated.i.e
if first radio button is selected then select box should
populate some set of values and if second radio button is
slected then selct box should be populated with other set
of values
Thanks in Advance
•
•
Join Date: Apr 2009
Posts: 13
Reputation:
Solved Threads: 1
You have to do a few different things. First ColdFusion being a Server Side Programming language, there is no way to do what you want using ColdFusion directly. You will have to use Javascript to dynamically link the drop down menus to an array that is populated by ColdFusion.
Another way to do it would be to have CF populate both dropdown menus and use javascript to control which is visible (using CSS) depending on which radio button you select.
I hope this puts you in the right direction.
Another way to do it would be to have CF populate both dropdown menus and use javascript to control which is visible (using CSS) depending on which radio button you select.
I hope this puts you in the right direction.
•
•
Join Date: Apr 2009
Posts: 13
Reputation:
Solved Threads: 1
Like I said there are a few different ways to do this. The following is what put together for you.
Put the following in the document head:
The above code does a few things. First it gets the data for the drop down menus by polling your database. If the data for these two menus are in the same table (which would make sense) you will need to include a WHERE clause in the above queries. These values are put into two drop down menus that appear or disappear depending on which radio button is checked. The following code will be found in the document body:
I hope this helps.
Put the following in the document head:
ColdFusion Syntax (Toggle Plain Text)
<cfquery datasource="yourDatasource" name="menu1"> SELECT value, option from SOME TABLE THAT HAS MENU1 DATA </cfquery> <cfquery datasource="yourDatasource" name="menu2"> SELECT value, option from SOME TABLE THAT HAS MENU2 DATA </cfquery> <script type="text/javascript"> function makeChange(form) { if (form.radio1[0].checked) { document.getElementById("showMenu1").style.visibility="visible"; document.getElementById("showMenu2").style.visibility="hidden"; form.menu2.selectedIndex = 0; } if (form.radio1[1].checked) { document.getElementById("showMenu2").style.visibility="visible"; document.getElementById("showMenu1").style.visibility="hidden"; form.menu1.selectedIndex = 0; } } </script> <style type="text/css"> #showMenu1 { visibility:hidden; } #showMenu2 { visibility:hidden; } </style>
The above code does a few things. First it gets the data for the drop down menus by polling your database. If the data for these two menus are in the same table (which would make sense) you will need to include a WHERE clause in the above queries. These values are put into two drop down menus that appear or disappear depending on which radio button is checked. The following code will be found in the document body:
ColdFusion Syntax (Toggle Plain Text)
<form action="" method="post"> <input type="radio" id="radio1" name="radio1" value="Yes" onClick="makeChange(this.form)" />Yes <input type="radio" id="radio1" name="radio1" value="No" onClick="makeChange(this.form)" />No <div id="showMenu1"> <select name="menu1"> <option value="" selected="selected">Select One</option> <cfoutput query="menu1"> <option value="#value#">#option#</option> </cfoutput> </select> </div> <div id="showMenu2"> <select name="menu2"> <option value="" selected="selected">Select One</option> <cfoutput query="menu2"> <option value="#value#">#option#</option> </cfoutput> </select> </div> </form>
I hope this helps.
•
•
Join Date: Apr 2009
Posts: 7
Reputation:
Solved Threads: 0
Thank u very much.....it solved my problem,.,,,,,,,now i have another
problem ....
I am displaying a dynamic table which consits of four columns named as Ingredient,Lot,d_amount,d_unit......out of which Ingredient,d_amount,d_unit are taken from one
query named as "qrecipes" i.e from one table and Lot Cloumn is taken from another table.Now the problem is the data that is to be displayed in lot column is dependent on the
data present in ingredient.i.e If the first row ingredient column has "XYZ" then i need to pick the id of "XYZ" from second table and display in lot column.
Ingredient Lot d_amount d_unit
1 xyx 345 is id
for XYZ which
should be
displayed from
Second table
Below is my code ....please say what is wrong .....please suggest me if there are any other methods or any kind of solution to solve this problem
Queirs
Table
problem ....
I am displaying a dynamic table which consits of four columns named as Ingredient,Lot,d_amount,d_unit......out of which Ingredient,d_amount,d_unit are taken from one
query named as "qrecipes" i.e from one table and Lot Cloumn is taken from another table.Now the problem is the data that is to be displayed in lot column is dependent on the
data present in ingredient.i.e If the first row ingredient column has "XYZ" then i need to pick the id of "XYZ" from second table and display in lot column.
Ingredient Lot d_amount d_unit
1 xyx 345 is id
for XYZ which
should be
displayed from
Second table
Below is my code ....please say what is wrong .....please suggest me if there are any other methods or any kind of solution to solve this problem
Queirs
coldfusion Syntax (Toggle Plain Text)
<cfquery name="qrecipes" datasource="testmsexcell"> SELECT * FROM Recipes WHERE product='#form.product#' </cfquery> <cfquery name="qlot" datasource="testmsexcell"> SELECT Lots.id FROM Lots WHERE ingredient='#qrecipes.ingredient#' </cfquery>
Table
html Syntax (Toggle Plain Text)
table border="2px" id="maketable"> <tr> <td>Ingredient</td> <td>Lot</td> <td>d_amount</td> <td>d_unit</td> </tr> <cfoutput query="qrecipes"> <tr> <td>#qrecipes.ingredient#</td> <td><cfselect name="lotid" id="lotid" query="qlot" value="id" display="id"></cfselect></td> <td>#qrecipes.d_amount#</td> <td>#qrecipes.d_unit#</td> </tr> </cfoutput> </table>
Last edited by peter_budo; Apr 21st, 2009 at 4:07 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
•
•
Join Date: Apr 2009
Posts: 7
Reputation:
Solved Threads: 0
Please neglete those dots.i have kept those for displaying tables properly
First Table is Recipes
Product...........ingredient.........d_amount.......... d_unit id
abc................xyz...............78................... lb.....
....................uvw...........................................
efg..................hig
......................lkm
In the first table the id is the primarykey which is autoincremented.
Second Table is Lot:The id is primarykey which is not related to first table which is recipes.
id.............ingredient
5t6y.............xyz
7yh8.............xyz
9jnu.............uvw
Now i am trying to diaplay to user something like this by taking product as input from the user.if the user selects product as "abc"
ingredient........lotids............d_amount.......d_unit
xyz...............5t6y
...................7yh8
uvw.................9jnu
I am able to display the ingredient,d_amount,d_unit correctly but i am unable to display the correct lotids for the repective ingredient.I am using CFSELECT tag to display the
lotids
First Table is Recipes
Product...........ingredient.........d_amount.......... d_unit id
abc................xyz...............78................... lb.....
....................uvw...........................................
efg..................hig
......................lkm
In the first table the id is the primarykey which is autoincremented.
Second Table is Lot:The id is primarykey which is not related to first table which is recipes.
id.............ingredient
5t6y.............xyz
7yh8.............xyz
9jnu.............uvw
Now i am trying to diaplay to user something like this by taking product as input from the user.if the user selects product as "abc"
ingredient........lotids............d_amount.......d_unit
xyz...............5t6y
...................7yh8
uvw.................9jnu
I am able to display the ingredient,d_amount,d_unit correctly but i am unable to display the correct lotids for the repective ingredient.I am using CFSELECT tag to display the
lotids
•
•
Join Date: Apr 2009
Posts: 13
Reputation:
Solved Threads: 1
Let me re-phrase what you are saying to see if I get it.
You have a table called recipes and a table called lots. These two tables are linked by ingredients. What you want is the user to be able to select a product and get from the database what the lot id is for the ingredient(s) that goes into the recipe.
This should be a pretty simple inner join.
Try the following query (making changes to the column names as needed):
If that works, let me know and I can get you the rest of the way.
You have a table called recipes and a table called lots. These two tables are linked by ingredients. What you want is the user to be able to select a product and get from the database what the lot id is for the ingredient(s) that goes into the recipe.
This should be a pretty simple inner join.
Try the following query (making changes to the column names as needed):
ColdFusion Syntax (Toggle Plain Text)
SELECT * from recipes r inner join lots l on l.lot_ingredient = r.ingredient
If that works, let me know and I can get you the rest of the way.
•
•
Join Date: Apr 2009
Posts: 7
Reputation:
Solved Threads: 0
Thanks the given sql is working ...it gave me correct data ..but now the problem is that it is displaying same data multipile times.i.e
ingredient........lotids............d_amount.......d_unit
xyz...............5t6y
xyz................7yh8
xyz................98uj
uvw.................9jnu
instead of that i need to display it as
xyz...............5t6y
..................7yh8
...................98uj
uvw.................9jnu
ingredient........lotids............d_amount.......d_unit
xyz...............5t6y
xyz................7yh8
xyz................98uj
uvw.................9jnu
instead of that i need to display it as
xyz...............5t6y
..................7yh8
...................98uj
uvw.................9jnu
•
•
Join Date: Apr 2009
Posts: 13
Reputation:
Solved Threads: 1
Re: how to populate a cfselect box depending upon the selection on raido button
0
#10 Apr 22nd, 2009
Humm... Maybe I do not understand what you are trying to do, because if you have two products with the same ingredient you will get duplication of that ingredient. I am not sure that is avoidable, however you should not be getting different lot_ids.
I am having trouble understanding your example tables. So I attached a screen shot of what I put together and maybe you can tell me what I am doing differently.
I am having trouble understanding your example tables. So I attached a screen shot of what I put together and maybe you can tell me what I am doing differently.
![]() |
Other Threads in the ColdFusion Forum
- Previous Thread: Has anybody tried the new Adobe Coldfusion?
- Next Thread: How to access cfdocument.currentpagenumber outside the cfdocumentitem tag
| Thread Tools | Search this Thread |





