<cfoutput> error for input type="checkbox"

Error when input type="checkbox" is empty

Page 1 of 1

1 Replies - 5287 Views - Last Post: 12 December 2007 - 10:58 PM Rate Topic: -----

#1 cmreedy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-December 07

<cfoutput> error for input type="checkbox"

Post icon  Posted 12 December 2007 - 04:30 PM

This is the code on the web page:
<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:
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:
<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>



Is This A Good Question/Topic? 0
  • +

Replies To: <cfoutput> error for input type="checkbox"

#2 sansclue   User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 316
  • Joined: 21-November 07

Re: <cfoutput> error for input type="checkbox"

Posted 12 December 2007 - 10:58 PM

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.

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>


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1