Usage of If else statement/condition with radio buttons

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kingka2
    New Member
    • Mar 2013
    • 1

    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:
    Code:
        <td><input type="radio" name="Env" value="DEV" checked >
                Dev</td> <td><input type="radio" name="Env" value="STG" checked >
                STG</td> <td><input type="radio" name="Env" value="PRD" checked >
                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
    Last edited by Rabbit; Mar 27 '13, 03:37 PM. Reason: Please use code tags when posting code.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    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:
    Code:
    <cfif form.env EQ "DEV">
        <cfquery ...>
    <cfelseif ...>
        <cfquery ...>
    If the queries are similar and the radio button selection only changes one line of the query, you could use something like:
    Code:
    <cfquery ...>
        <cfif form.Env EQ "DEV">
            <!--- DEV specific SQL --->
        <cfelseif ...>
    One last thing: cfswitch is an alternative to if/else.

    Comment

    Working...