ColdFusion Tips and Tutorials

ColdFusion Tips and Tutorials. Tips on ColdFusion, AJAX, CSS, JavaScript, HTML, Design, and more.

CFUnited Developer Conference 2010
Use this code TIPSCUST to get $100 off your registration @ CFUnited! We'll see you There!


ColdFusion Tips
Page 1 2 3
148 ColdFusion, Ajax, FuseBox, Tips, and Tut
147 Included Point of View
146 Javascript - OnFocus
145 Nathan's Rules of Professional Web Desig
144 Universal Server-Side Check | Bandwidth
143 Meeting Schedule | Identification Sessio
142 Breaking Frames Without Javascript
141 Unreal Forms
140 Screen Resolution
139 Human Help
138 Better Server-Side Validation
137 Automatic Server-Side Validation
136 Regular Expression Laboratory,ColdFusion
135 Rank-Ordered Site Search
134 Building Cryptograms
133 Well-Formed Includes
132 Grouping Families for Visits
131 Display Families on a Map Grid
130 Slide Shows
129 Determine Your Database Engine
128 ColdFusion in Context: Maxlength Lies
127 Something Extra
126 Parsing Database Structure from Data Def
125 Valid Values Maintenance
124 Print 1
123 Hide Session Id
122 Downsizing Data to Access
121 Time to Load a Page, FuseBox 4
120 Order and Rank by Subset
119 Warn through E-mail & Update on Paste Sp
118 Paste Spreadsheets, ColdFusion Component
117 Review Files Having Fixed-Length Fields
116 Organized Help
115 Sequence Slider
114 Bad Bits
113 Logical Deduction
112 Whiteout
111 Forced Navigation
110 Managing Permissions
109 Time Travel
108 Test First
107 Get Distance Between Map Coordinates
106 Validating Checkboxes
105 Matrix Manipulation
104 Field Help
103 Fake Object Not Found
102 Rank Order Correlation Coefficient
101 From Calling Pairs to Calling Tree
100 Posting Notice
99 Logout Persuasion
98 Release Session Memory
97 Use Identically Named Fields
96 Web Bug
95 Password Generation
94 Core Queries
93 Use CFFTP
92 Insert, Update, and Delete
91 Stack
90 T-Value
89 Bulk Data Entry and E-mail Validation
88 Quick Reset
87 Design 1
86 Use CFFTP
85 Support Login with AutoPost
84 Login and Site Protection
83 XY Graphs in a Graphing Calculator
82 Read Encrypted Files
81 Showing Progress
80 Frugal Cross-Browser Javascript
79 Tabbed Folders
Page 1 2 3



Custom Search
ColdFusion TIPS PLUS


Issue 00106 http://www.cftipsplus.com

I. My Comments

II. ColdFusion In Context: Validating Checkboxes
By R. Martin Ladner
martin.ladner@knology.net



See our sponsors at the bottom of this e-mail.

I. Comments:

Hope your doing well. I am doing well had a great summer. Now the kids will be headed back to school. For those Mom's at home I am sure they are ready for the break.


Keep Coding,
Nathan Stanford
http://www.cftipsplus.com

If you have suggestions for articles send them to us.
If you would like to write for cftipsplus.com
send us an email to:

admin@cftipsplus.com

IF YOU WANT TO BE AN AUTHOR SEND IN YOUR COLDFUSION TIPS.

Remember this is a great way to get your name known in the
ColdFusion Community.



II. ColdFusion in Context: Validating Checkboxes
By R. Martin Ladner
martin.ladner@knology.net



It's easy to read text fields on the client's browser to confirm that the values they contain meet various specifications. However, suppose you want to confirm on the client's browser that a combination of checkboxes chosen by the user fits your requirements. You can't look for checkbox values values the same way you would read text boxes. This tip gives a method that works.

Checkbox Theory
Checkboxes usually come in groups, are identically named within those groups, and are read two different ways depending on whether you're on the client using javascript or on the server using ColdFusion. On the client, you refer to checkboxes in a group by position (starting with zero), and read the "checked" property instead of reading their values directly. On the server, the checked values for the entire group come in as a single, comma-delimited string.

Start with the End
To keep things simple, give the string a default value; then, display the string if it isn't zero length. Put all this code in checkbox.cfm.

<pre>
<cfparam name="form.CustomerType" default="">
<cfif len(trim(form.CustomerType))>
Here's the list of what you checked:
<cfoutput>#form.CustomerType#</cfoutput>
</cfif>

Create Two Functions
Suppose you want to be sure that the user checked at least one box, and you don't want the user to be able to submit the page unless this is true. One function you'll need is something to check the boxes. Another function you'll need is something to consider if it's OK to submit the form.
For checking the boxes, you'll need to treat all the boxes in the group as an array and use an index to refer to a specific member of the array. (Remember that all the boxes in a single group have the same name; so, this treatment is necessary.) The "checked" property is either true or false (one hopes). The form to be used has two boxes in one group. The boxes are named CustomerType. If boxcheck finds that both boxes are empty, it returns "false". If it returns false, then the "consider" function, invoked when the user clicks a button on the form, fails to submit the form. Convesely, if one or both boxes are checked, clicking the button submits the form.


<script>
function boxcheck()
{
if (document.demo.CustomerType[0].checked == false)
{
if (document.demo.CustomerType[1].checked == false)
{
alert('Please indicate if you are a consumer, producer, or both');
return false;
}
}
return true;
}

function consider()
{
if (!boxcheck()) return false;
document.demo.submit();
return true;
}
</script>

Build the Form
Because we started with the end and worked backwards, the form is anti-climatic. It has a couple of checkboxes and a button that's used to consider submission of the form.

<form name="demo" action="checkbox.cfm" method="post">
Please indicate your status:<br>
<input type="checkbox" name="CustomerType" value="Consumer">Consumer<br>
<input type="checkbox" name="CustomerType" value="Producer">Producer<br>
<input type="button" name="run" value="Submit" onClick="consider()">
</form>

Try it Out
Browse checkbox.cfm. Consider that radio buttons work in a similar fashion (in that they have to be read as part of an array on the client side). Then use this concept in your work.

=Marty=



SPONSOR ADS:
This e-mail is sponsored by the following ads.

Sponsored Ad

Books For Sale
http://nsnd.vstorelibrary.com/



Advanced, Intensive ColdFusion Training!
Visit this site. If you have plans to get training here is a company
that provides Advanced, Intensive ColdFusion Training. Check them out.
http://www.coldfusiontraining.com/index.cfm?ref=cftipsplus



Sponsored Ad


Publisher and Creator:
Nathan Stanford,
admin@cftipsplus.com
http://www.cftipsplus.com

Macromedia and ColdFusion are U.S. registered trademarks.


Copyright (c) 2000 - 2002 CFTIPSPLUS.COM and NSND.COM
Permission is granted to circulate this publication via
MANUAL forwarding by email to friends provided that the text is
forwarded in its entirety and no fee is charged.

Photo of Nathan Stanford
Nathan Stanford
LinkedIn

R. Marty Ladner's
Site