0
Explorer
,
/t5/coldfusion-discussions/assign-session-variables-to-radio-buttons/td-p/1012047
Jul 28, 2006
Jul 28, 2006
Copy link to clipboard
Copied
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.
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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
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. 🙂
eg. <input type=radio name="ccheck" value="YES" <CFIF session.variable EQ 'YES'>checked</CFIF>....
EDIT: Err what he said. 🙂
Contributor
,
/t5/coldfusion-discussions/assign-session-variables-to-radio-buttons/m-p/1012048#M91823
Jul 28, 2006
Jul 28, 2006
Copy link to clipboard
Copied
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
<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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Lumpia
AUTHOR
Explorer
,
/t5/coldfusion-discussions/assign-session-variables-to-radio-buttons/m-p/1012051#M91826
Jul 28, 2006
Jul 28, 2006
Copy link to clipboard
Copied
For whatever reason, I cannot get this to work. I have tried
numerous variations of this code and no luck. Any other
ideas?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Contributor
,
/t5/coldfusion-discussions/assign-session-variables-to-radio-buttons/m-p/1012053#M91828
Jul 28, 2006
Jul 28, 2006
Copy link to clipboard
Copied
Output session.ccheck to what the value is. Maby that's not
being set right or you have to adjust your CF settings.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/assign-session-variables-to-radio-buttons/m-p/1012052#M91827
Jul 28, 2006
Jul 28, 2006
Copy link to clipboard
Copied
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?
<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?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Beginner
,
/t5/coldfusion-discussions/assign-session-variables-to-radio-buttons/m-p/1012049#M91824
Jul 28, 2006
Jul 28, 2006
Copy link to clipboard
Copied
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. 🙂
eg. <input type=radio name="ccheck" value="YES" <CFIF session.variable EQ 'YES'>checked</CFIF>....
EDIT: Err what he said. 🙂
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Engaged
,
/t5/coldfusion-discussions/assign-session-variables-to-radio-buttons/m-p/1012050#M91825
Jul 28, 2006
Jul 28, 2006
Copy link to clipboard
Copied
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!
checked="checked"
checked on its own will work but it is not XHTML compliant!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Lumpia
AUTHOR
Explorer
,
LATEST
/t5/coldfusion-discussions/assign-session-variables-to-radio-buttons/m-p/1012054#M91829
Jul 31, 2006
Jul 31, 2006
Copy link to clipboard
Copied
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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

