Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preload Checkbox\Radio Button Value

Status
Not open for further replies.

RAxel

MIS
Sep 8, 2005
121
US
Hi all, I'm new to coldfusion mx so bear with me. :)

This is the scenario. A user takes a survey, when completed the answers are sent to a database. The user can then review their answers, edit anything and resubmit.

What I want to do is when they review their answers, is to display the same questions/answers/format that they had when they first entered their answers, however, this time, the checkboxes/radio buttons/text boxes will have their information already loaded with the answers they gave.

For starters, how can I preselect a checkbox or radio button to be checked or not checked? What is the attribute?

Also, I was thinking about looping through the fieldnames (which I believe is form.fieldnames?) in the form. Is it possible to figure out their type? For example, a textbox of type text, checkbox of type checkbox, and so on... What is the syntax for that?

Thanks for your help.
 
Thanks for the reply.

On "Page 5 - How's Your Memory?" of the tutorial, does this work even when a user logs out and logs back in? And it only pertains to that user? Or is it the last value regardless of who did it?

If it works separately for each user than that's what I need, else, I may need to do a cookie.
 
Hmm, Coldfusion MX doesn't seem to like the # signs in the value field. I just get a "Variable (whatever the value is) is undefined" error.

 
if you are using # s as text in a cfml proccesable area, you need to escape it like ##

so <cfoutput>##</cfoutput> will display #

 
Yep, imstillatwork is correct, obviously the # symbol is used commonly to define things in a .cfm document so you have to double up.

I've not used the forms using a user login RAxel, i'm still new to ColdFusion myself, but spotted that Tutorial and thought of you.

I think from memory that the Tutorial does explain using cookies to save particular settings such as this ... but provided you logged thier previous answers in the database you should be able to draw on those as reference.

So for instants, first time i fill in a form i choose my name as "Rob" .. when i go back another time and want to Edit the record it should display "Rob" as my default value, I think you will find that Radio buttons and check boxes store data as a "yes/no" variable, atleast thats how Microsoft Access and MySQL work.

You have to keep in mind that when the person returns to fill in the form again they are no longer Adding a new record, they are Editing an old one.

My knowledge is pretty limited, but that is the direction you want to head in.

Rob
 
you can use cookies to save user information even during a browser close. so even if the user logs, and the cookie variables indicating a logged out user exists, other variables in the cookie can still be used for other things.

even if you are using cflogin, you can set cookies to expire whenever you want to save other information for that user, logged on or not.

 
But don't I have to make sure the user has security settings low enough to accept the cookies? Or if they have a virus scanning software that'll delete it?
 
Let me say this as it might clear things up. The people who designed the web pages in coldfusion have it setup like this:

Question 1:
RB name = Q01 value = Q01A
RB name = Q01 value = Q01B
RB name = Q01 value = Q01C
.
.
.
Question 2:
RB name = Q02 value = Q02A
RB name = Q02 value = Q02B
.
.
.

RB = radio button
Some radio buttons have checkboxes underneath them and some don't.

So, when I first was told to pre-load their answers, I thought there was a way to loop through the fields, check their value against what was sent to the database and then do something like what I have below if their value equals what is in the database:

RB.checked = true (I don't know the correct syntax)

Is something like this possible in ColdFusion?

Thanks.
 
the names and values of checkboxes are html only, but you can store an identical name and value in cold fusion.

so using persistant session varialbes or cookies, you can, on the action page of this form save the form variables (Q01,Q02, etc, including the checkboxes) to session variables like session.Q01 = Q01A, session.Q02 = Q02A

now you have a copy of the users answers in a coldfusion varaible.

when the form page is loaded, you can check for these answers and mark the input as checked or not. ColdFusion has no real control over the form as to checking or unchecking, bu you can manipulate the html code before it gets sent to the browser to make a checkbox or readio checked or not.

Use cfparam to set the default values, this way there are variables with a default value, so we can call the variable without worring about it being defined or not, even if we have not set them yet.

<cfparam name="session.Q01" default="">

<input type="checkbox" name="Q01" value="Q01A" <cfif session.Q01 EQ Q01A>checked="checked"</cfif>



 
Thanks a lot imstillatwork.

If I understand correctly, and please correct me if I'm wrong, a session is made at the time the user is logged in. So long as the user stays logged in, I should be able to use the session to load their selected answers.

However, using 'session' can this be used when a user logs out and then logs back in? Or are the answers lost?

Thanks.
 

Read the CFML Reference for session variables.

Actually, read the entire thing.

session scope variables can last as long as specified. By 'logged on' or 'logged off' do you mean entering a name/password or just visiting the page? A session scope vairable has nothing to do with a user 'logged on' or 'logged off' with a name and password, it is a way to persistantly remember variables over a time span, rather than just a current page request. Session variables work much like cookies in that they can store information over time period, available only to the current user, available to any template. Sessions have many advantages over cookies.



read read read, and build the examples on your server to see how they work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top