Welcome to Dream.In.Code
Getting Help is Easy!

Join 117,542 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,706 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



<cfoutput> error for input type="checkbox"

 
Reply to this topicStart new topic

<cfoutput> error for input type="checkbox", Error when input type="checkbox" is empty

cmreedy
post 12 Dec, 2007 - 04:30 PM
Post #1


New D.I.C Head

*
Joined: 12 Dec, 2007
Posts: 1


My Contributions


This is the code on the web page:
CODE

<p>Scope of Practice (check all that apply):<br>      
<input type="checkbox" name="ScopeOfPractice1" Value="ER">&nbsp;ER&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" name="ScopeOfPractice2" Value="Inpatient">&nbsp;Inpatient&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" name="ScopeOfPractice3" Value="Newborns">&nbsp;Newborns&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" name="ScopeOfPractice4" Value="NursingHome">&nbsp;Nursing Home<br>
<input type="checkbox" name="ScopeOfPractice5" Value="HouseCalls">&nbsp;House Calls&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" name="ScopeOfPractice6" Value="OB">&nbsp;OB&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" name="ScopeOfPractice7" Value="SurgicalAssisting">&nbsp;Surgical Assisting&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" name="ScopeOfPractice8" Value="SurgeryProcedures">&nbsp;Surgery Procedures</p>

The .cfm file sends an email and also shows the user what they sent. It works if all of the checkboxes are checked. But if one of the above checkboxes is not marked, I get an error. How do I make a <cfif> statement to see if the box is checked?
Here is the code for the email after the <cfmail> tag:
CODE

Scope of Practice: #Form.ScopeOfPractice1#
#Form.ScopeOfPractice2#
#Form.ScopeOfPractice3#
#Form.ScopeOfPractice4#
#Form.ScopeOfPractice5#
#Form.ScopeOfPractice6#
#Form.ScopeOfPractice7#
#Form.ScopeOfPractice8#
#Form.ScopeOfPractice9#

And here is the relevant code for the webpage that the user sees:
CODE

<cfoutput> Thank you! Below is the information you sent:<br><br>
Scope of Practice: #Form.ScopeOfPractice1# #Form.ScopeOfPractice2#
#Form.ScopeOfPractice3#
#Form.ScopeOfPractice4#
#Form.ScopeOfPractice5#
#Form.ScopeOfPractice6#
#Form.ScopeOfPractice7#
#Form.ScopeOfPractice8#
#Form.ScopeOfPractice9#
</cfoutput>

User is offlineProfile CardPM

Go to the top of the page


sansclue
post 12 Dec, 2007 - 10:58 PM
Post #2


D.I.C Head

**
Joined: 21 Nov, 2007
Posts: 87



Thanked 4 times
My Contributions


Checkbox elements don't exist if they weren't checked. Either use IsDefined() to determine if they exist before using them, or use <cfparam> to define default a value for them.

But I think what you want here is to give all the checkboxes on the form the same name. The checked values will be submitted as a comma delimited list that you can loop through.

CODE

FORM
<p>Scope of Practice (check all that apply):<br>      
<input type="checkbox" name="ScopeOfPractice" Value="ER"> ER    
<input type="checkbox" name="ScopeOfPractice" Value="Inpatient"> Inpatient    
<input type="checkbox" name="ScopeOfPractice" Value="Newborns"> Newborns    
<input type="checkbox" name="ScopeOfPractice" Value="NursingHome"> Nursing Home<br>
.....

ACTION PAGE
<cfparam name="FORM.scopeOfPractice" default="">
<cfif listLen(FORM.scopeOfPractice)>
    The boxes you checked are:<br>
    <cfoutput>
    <cfloop list="#FORM.scopeOfPractice#" index="theScope">
        #theScope#<br>
    </cfloop>
    </cfoutput>
<cfelse>
    Sorry, you didn't check anything    
</cfif>
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/7/08 05:39PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month