School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,157 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,555 people online right now. Registration is fast and FREE... Join Now!




<cfoutput> error for input type="checkbox"

 

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

cmreedy

12 Dec, 2007 - 03: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
+Quote Post


sansclue

RE: <cfoutput> Error For Input Type="checkbox"

12 Dec, 2007 - 09:58 PM
Post #2

D.I.C Regular
***

Joined: 21 Nov, 2007
Posts: 316



Thanked: 28 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
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 05:47PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month