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

Assign Session Variables to Radio Buttons

Explorer ,
Jul 28, 2006 Jul 28, 2006
Sorry if this may have been partially answered in another post, but I can seem to find the answer.

I have a form that contains radio buttons, along with other form fields. If the user hits the submit button, it takes them to a processing page which has alot of validation checks, spits an error message out to the user, and displays a 'go back' button to return to the previous page for corrections.

All of my text input boxes have session variables assigned to the 'value' field and they all work great. After the user hits the go back button, the data is re-populated back in the fields. However, I cannot figure out how to assign a session variable to my radio buttons. Here is my code:

<cfinput required="yes" message="You must Indicate Y or N for timeframe - work during C-Check" type="radio" value="YES" name="ccheck">YES
<cfinput required="yes" message="You must Indicate Y or N for timeframe - work during C-Check" type="radio" value="NO" name="ccheck">NO

You can see that unlike text boxes, the value field is already populated, so I am confused as to where to add the session variable. Here is what my text input field looks like:

<cfinput type="text" name="ccheck_total" size="8" validate="integer" message="The Total Aircraft field can only contain numbers." value="#session.ccheck_total#">

I'm fairly sure I will need an <cfif> statement on my processing page, but am confused how to code it. Please assist.
1.2K
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

correct answers 1 Correct answer

Community Beginner , Jul 28, 2006 Jul 28, 2006
In HTML you just add CHECKED to the <INPUT> line. I would think off hand cfinput is similar. You could then cfif CHECKED based on the session value (YES or NO)

eg. <input type=radio name="ccheck" value="YES" <CFIF session.variable EQ 'YES'>checked</CFIF>....

EDIT: Err what he said. 🙂
Translate
Contributor ,
Jul 28, 2006 Jul 28, 2006
First, I would set a variable incase your session is not defined somewhere above the radiobutton:
<CFIF NOT Isdefined("Session.ccheck")>
<CFSEt ccheck = "">
<CFELSE>
<CFSET ccheck = session.ccheck>
</CFIF>

Then in your radio buttons:
<cfinput required="yes" message="You must Indicate Y or N for timeframe - work during C-Check" type="radio" value="YES" name="ccheck"<CFIF ccheck IS "Yes"> Checked</CFIF>>Yes
<cfinput required="yes" message="You must Indicate Y or N for timeframe - work during C-Check" type="radio" value="NO" name="ccheck""<CFIF ccheck IS "No"> Checked</CFIF>>NO
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
Explorer ,
Jul 28, 2006 Jul 28, 2006
For whatever reason, I cannot get this to work. I have tried numerous variations of this code and no luck. Any other ideas?
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
Contributor ,
Jul 28, 2006 Jul 28, 2006
Output session.ccheck to what the value is. Maby that's not being set right or you have to adjust your CF settings.

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 ,
Jul 28, 2006 Jul 28, 2006
A couple of ways that this can be done;

<cfinput required="yes" message="You must Indicate Y or N for timeframe
- work during C-Check" type="radio" value="YES" name="ccheck"<CFIF
session.ccheck IS "Yes">Checked</CFIF>>Yes

<cfinput required="yes" message="You must Indicate Y or N for timeframe
- work during C-Check" type="radio" value="NO" name="ccheck""<CFIF
session.ccheck IS "No">Checked</CFIF>>>NO

OR

<cfinput required="yes" message="You must Indicate Y or N for timeframe
- work during C-Check" type="radio" value="YES" name="ccheck" #IIF
session.ccheck IS "Yes", DE("Checked"),DE(""))#>>Yes

<cfinput required="yes" message="You must Indicate Y or N for timeframe
- work during C-Check" type="radio" value="NO" name="ccheck"" #IIF
session.ccheck IS "No", DE("Checked"),DE(""))#>>NO


Lumpia wrote:
> For whatever reason, I cannot get this to work. I have tried numerous variations of this code and no luck. Any other ideas?
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
Community Beginner ,
Jul 28, 2006 Jul 28, 2006
In HTML you just add CHECKED to the <INPUT> line. I would think off hand cfinput is similar. You could then cfif CHECKED based on the session value (YES or NO)

eg. <input type=radio name="ccheck" value="YES" <CFIF session.variable EQ 'YES'>checked</CFIF>....

EDIT: Err what he said. 🙂
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 ,
Jul 28, 2006 Jul 28, 2006
Just as a side note, the correct syntax for checked radio button is

checked="checked"

checked on its own will work but it is not XHTML compliant!
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
Explorer ,
Jul 31, 2006 Jul 31, 2006
LATEST
Thanks everyone for your replies. They all helped very much. I would like to say that regarding nesting <cfif> statements... they cannot be nested within a <cfinput> tag. You can nest a <cfif> statement within a normal <input> tag, which happened to solve my problem. Again, thanks everyone for their comments/suggestions as they all helped.
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