how to populate a cfselect box depending upon the selection on raido button

Reply

Join Date: Apr 2009
Posts: 7
Reputation: nagkar is an unknown quantity at this point 
Solved Threads: 0
nagkar nagkar is offline Offline
Newbie Poster

how to populate a cfselect box depending upon the selection on raido button

 
0
  #1
Apr 10th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 13
Reputation: wblakenc is an unknown quantity at this point 
Solved Threads: 1
wblakenc wblakenc is offline Offline
Newbie Poster

Re: how to populate a cfselect box depending upon the selection on raido button

 
0
  #2
Apr 12th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 7
Reputation: nagkar is an unknown quantity at this point 
Solved Threads: 0
nagkar nagkar is offline Offline
Newbie Poster

Re: how to populate a cfselect box depending upon the selection on raido button

 
0
  #3
Apr 19th, 2009
Thanks for the reply can you give me some example using code.......
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 13
Reputation: wblakenc is an unknown quantity at this point 
Solved Threads: 1
wblakenc wblakenc is offline Offline
Newbie Poster

Re: how to populate a cfselect box depending upon the selection on raido button

 
0
  #4
Apr 20th, 2009
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:

  1. <cfquery datasource="yourDatasource" name="menu1">
  2. SELECT value, option
  3. from SOME TABLE THAT HAS MENU1 DATA
  4. </cfquery>
  5.  
  6. <cfquery datasource="yourDatasource" name="menu2">
  7. SELECT value, option
  8. from SOME TABLE THAT HAS MENU2 DATA
  9. </cfquery>
  10.  
  11.  
  12. <script type="text/javascript">
  13.  
  14. function makeChange(form) {
  15. if (form.radio1[0].checked) {
  16. document.getElementById("showMenu1").style.visibility="visible";
  17. document.getElementById("showMenu2").style.visibility="hidden";
  18. form.menu2.selectedIndex = 0;
  19.  
  20. }
  21. if (form.radio1[1].checked) {
  22. document.getElementById("showMenu2").style.visibility="visible";
  23. document.getElementById("showMenu1").style.visibility="hidden";
  24. form.menu1.selectedIndex = 0;
  25.  
  26. }
  27. }
  28.  
  29.  
  30. </script>
  31. <style type="text/css">
  32. #showMenu1 {
  33. visibility:hidden;
  34. }
  35. #showMenu2 {
  36. visibility:hidden;
  37. }
  38. </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:

  1. <form action="" method="post">
  2. <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
  3. <div id="showMenu1">
  4.  
  5. <select name="menu1">
  6. <option value="" selected="selected">Select One</option>
  7. <cfoutput query="menu1">
  8. <option value="#value#">#option#</option>
  9. </cfoutput>
  10. </select>
  11. </div>
  12.  
  13. <div id="showMenu2">
  14.  
  15. <select name="menu2">
  16. <option value="" selected="selected">Select One</option>
  17. <cfoutput query="menu2">
  18. <option value="#value#">#option#</option>
  19. </cfoutput>
  20. </select>
  21. </div>
  22. </form>


I hope this helps.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 7
Reputation: nagkar is an unknown quantity at this point 
Solved Threads: 0
nagkar nagkar is offline Offline
Newbie Poster

Re: how to populate a cfselect box depending upon the selection on raido button

 
0
  #5
Apr 20th, 2009
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

  1. <cfquery name="qrecipes" datasource="testmsexcell">
  2. SELECT *
  3. FROM Recipes WHERE product='#form.product#'
  4.  
  5. </cfquery>
  6.  
  7.  
  8. <cfquery name="qlot" datasource="testmsexcell">
  9. SELECT Lots.id
  10. FROM Lots WHERE ingredient='#qrecipes.ingredient#'
  11. </cfquery>


Table

  1. table border="2px" id="maketable">
  2. <tr>
  3.  
  4. <td>Ingredient</td>
  5. <td>Lot</td>
  6. <td>d_amount</td>
  7. <td>d_unit</td>
  8. </tr>
  9. <cfoutput query="qrecipes">
  10. <tr>
  11.  
  12. <td>#qrecipes.ingredient#</td>
  13. <td><cfselect name="lotid" id="lotid" query="qlot" value="id" display="id"></cfselect></td>
  14. <td>#qrecipes.d_amount#</td>
  15. <td>#qrecipes.d_unit#</td>
  16. </tr>
  17. </cfoutput>
  18. </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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 13
Reputation: wblakenc is an unknown quantity at this point 
Solved Threads: 1
wblakenc wblakenc is offline Offline
Newbie Poster

Re: how to populate a cfselect box depending upon the selection on raido button

 
0
  #6
Apr 20th, 2009
Can you not just join the two tables using an inner join?
I suspect you can do what you need with one query, but I have to know more about your table design with the primary and foreign keys.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 7
Reputation: nagkar is an unknown quantity at this point 
Solved Threads: 0
nagkar nagkar is offline Offline
Newbie Poster

Re: how to populate a cfselect box depending upon the selection on raido button

 
0
  #7
Apr 20th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 13
Reputation: wblakenc is an unknown quantity at this point 
Solved Threads: 1
wblakenc wblakenc is offline Offline
Newbie Poster

Re: how to populate a cfselect box depending upon the selection on raido button

 
0
  #8
Apr 20th, 2009
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):
  1. SELECT *
  2. 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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 7
Reputation: nagkar is an unknown quantity at this point 
Solved Threads: 0
nagkar nagkar is offline Offline
Newbie Poster

Re: how to populate a cfselect box depending upon the selection on raido button

 
0
  #9
Apr 21st, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 13
Reputation: wblakenc is an unknown quantity at this point 
Solved Threads: 1
wblakenc wblakenc is offline Offline
Newbie Poster

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.
Attached Thumbnails
recipesTable.jpg   lotTable.jpg  
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC