Skip to main content
lovewebdev
Inspiring
April 3, 2009
Question

Using CFIF in CFINPUT radio tag

  • April 3, 2009
  • 3 replies
  • 6393 views
I'm a little new to using cfinput. I always use HTML input.

I have radio buttons for gender. When the form is submitted, the value is entered into a db column 1 or 2:
<cfinput name="g" id="g" type="radio" value="1" required="yes" />  F<cfinput name="g" id="g" type="radio" value="2" />

I want to check one by default depending on the value stored in the db column when the form loads.

I'm able to use a CFIF statement to check one by default in the HTML radio like:
<cfif rs.g eq 1>checked="true"</cfif>

but you're not allowed to have cfif in a single cfinput tag.

How do I do it.
    This topic has been closed for replies.

    3 replies

    Inspiring
    April 11, 2009

    Use an input tag instead of a cfinput tag.

    Inspiring
    April 10, 2009

    Hi lovewebdev,

    If I understand correctly what it is your trying to accomplish, try something like this.

    <cfif rs.g eq 1>

    <cfinput type="radio" checked="yes">F <cfinput type="radio" checked="no">M

    <cfelseif rs.g eq 2>

    <cfinput type="radio" checked="no">F <cfinput type="radio" checked="yes">M

    </cfif>

    So based on the value of the db column, the correct form elements will display

    and the right one should be checked.

    Leonard B

    April 8, 2009

    Hi lovewebdev,

    You can just put the condition directly in the checked attribute of your form field, like so:

    <cfinput name="g" id="g" type="radio" value="1" required="yes" checked="#rs.g eq 1#" />

    The checked attribute accepts True or False, so you can put any condition you'd like in there.

    Daniel Short

    Adobe Community Expert    

    Participant
    May 22, 2013

    Thanks!!!