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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check boxes 1

Status
Not open for further replies.

zunal2000

Technical User
Nov 6, 2002
5
0
0
US
Hi
I am a newbie on Coldfusion and I love it.And also I love this form.. thanks people.
I have a difficulty on something explained below, I searched the whole forum last night and could not find an answer for me and I decided to write. Please help me with this problem..

I am working on a project in which I need to update a list of checkboxes on people's preferences..
In short it is a book review project, people include their name, email, and comments about a book.

Name (textbox)
Email (textbox)
Book was helpful(checkbox)
I read the book before (checkbox)
I recommend the book (checkbox)
...
...
...

I am not having difficulty adding new people and their comments. But when when I try updating information I am having difficulty showing people's preferences that they included before as checkboxes and also I do not know how to help them to update..

Such as if somebody selected "yes" for the question "book was helpful" and want to change his idea as "no" what kind of coding I should add to the checkboxes..
I am a little bit confused on this coding. I tried

<CFIF #WasHelpful# eq 1>
<cfinput name=&quot;WasHelpful&quot; type=&quot;checkbox&quot; checked=&quot;yes&quot;>
<cfelse>
<cfinput name=&quot;WasHelpful&quot; type=&quot;checkbox&quot;>
</CFIF>

With this code it is showing what his answer was before but if I unselect it or leave it unselected I get a message &quot;WasHelpful&quot; variable is undefined...
Thank you very much for your help...

 
Checkboxes unchecked do not return any result, hence the undefined message. Try:
Code:
<CFIF isDefined('WasHelpful')>
<cfinput name=&quot;WasHelpful&quot; type=&quot;checkbox&quot; checked=&quot;yes&quot;>
<cfelse>
<cfinput name=&quot;WasHelpful&quot; type=&quot;checkbox&quot;>
</CFIF>
If it is defined that means it was checked.
DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Hi, DeZiner
First of all thank you for your quick answer.
I tried your code with the project. It seems working. It is exactly showing If people checked/unchecked before. But if I leave something unchecked or if I unchecked something that was checked before I get the same error Variable is undefined....
Do you have any idea why I am getting this error?

Should I do somehting in my update page too?
<Cfquery datasource=&quot;books&quot;>
Update Review
Set ReviewID='#Trim(Form.ReviewID)#',
Name='#Trim(Form.ModelID)#',
Email='#Trim(Form.Email)#',
Washelpful='#Trim(Form.Washelpful)#',
Recommend='#Trim(Form.Recommend)#',
ReadBefore='#Trim(Form.ReadBefore)#',
Where ReviewID=#Form.ReviewID#
</Cfquery>


 
YES, again if it is not checked then during the update statement you will get an error. You can use:

<cfif isDefined('form.Washelpful')>
<cfset Washelpful = 1>
<cfelse>
<cfset Washelpful = 0>
</cfif>

<Cfquery datasource=&quot;books&quot;>
Update Review
Set ReviewID='#Trim(Form.ReviewID)#',
Name='#Trim(Form.ModelID)#',
Email='#Trim(Form.Email)#',
Washelpful='#Trim(Washelpful)#',
Recommend='#Trim(Form.Recommend)#',
ReadBefore='#Trim(Form.ReadBefore)#',
Where ReviewID=#Form.ReviewID#
</Cfquery>

This will ensure that washelpfull contains something during the update. You can use cfparam as well. DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
I wish I could give you 5 stars...
Thanks again, you never know how much you've helped me..
Best wishes......
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top