469,283 Members | 2,303 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,283 developers. It's quick & easy.

Usage of If else statement/condition with radio buttons

Hi all,
I have created three radio buttons in my coldfusion page and working fine. But now i want to execute query, depending on the button selected.
ex:
Expand|Select|Wrap|Line Numbers
  1.     <td><input type="radio" name="Env" value="DEV" checked >
  2.             Dev</td> <td><input type="radio" name="Env" value="STG" checked >
  3.             STG</td> <td><input type="radio" name="Env" value="PRD" checked >
  4.             PRD</td>
My criteria is to execute a query related to Dev environment when Dev selected,
Execute a query related to STG environment when STG selected,
execute a query related to PRD environment when PRD selected
and to display the results.

My query is working fine but got struck at the if else loop
Kindly help me in achieving this. Thanks in advance
Mar 27 '13 #1
1 6865
acoder
16,027 Expert Mod 8TB
With radio buttons, the value is only passed if one of the buttons is selected. You can set a default with cfparam.

I see that you've checked all of the buttons. You should only have one selected by default. The browser will only select one anyway, but it will probably be the last one.

Are the queries very different? If so, you can simply use something like:
Expand|Select|Wrap|Line Numbers
  1. <cfif form.env EQ "DEV">
  2.     <cfquery ...>
  3. <cfelseif ...>
  4.     <cfquery ...>
If the queries are similar and the radio button selection only changes one line of the query, you could use something like:
Expand|Select|Wrap|Line Numbers
  1. <cfquery ...>
  2.     <cfif form.Env EQ "DEV">
  3.         <!--- DEV specific SQL --->
  4.     <cfelseif ...>
One last thing: cfswitch is an alternative to if/else.
Apr 9 '13 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by DettCom | last post: by
4 posts views Thread by Oscar Monteiro | last post: by
7 posts views Thread by reon | last post: by
2 posts views Thread by pradeep.thekkottil | last post: by
4 posts views Thread by Blasting Cap | last post: by
10 posts views Thread by =?Utf-8?B?UGFycm90?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.