Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using CFIF in CFINPUT radio tag

Participant ,
Apr 03, 2009 Apr 03, 2009
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.
6.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 08, 2009 Apr 08, 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    

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 22, 2013 May 22, 2013
LATEST

Thanks!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 09, 2009 Apr 09, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 11, 2009 Apr 11, 2009

Use an input tag instead of a cfinput tag.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources