> I need to dynamically create some javascript adding event
> handlers to form elements. So, I do something like so in
> CF Code:
>
> <cfscript>
> for (field in Form) {
> WriteOutput("document.forms[0].#field#.onclick
> = EventHandler;
> }
> </cfscript>
>
> now, this works fine, and I get the javascript block I'm
> expecting. However, the #field# section translates to an
> UPPER case field name. This would be fine, if my form elements
> were also in uppercase. But, they are using mixed case. (and
> having 200+ form elements will result in a great deal of
> time to convert these to all upper case)
>
> Is there anyway to make CF output the name of a form element
> using the "original" case??
>
> I've worked around this for now using some creative JS and an
> associative array, but if I can avoid that, my page is already
> doing too much, and a little slow to load as it is - I need to
> optimize this where I can.
As you've discovered, CF doesn't store variable names as case-sensitive
values. So, you won't be able to find out this information by looking at the
Form scope. Here are some options.
1. Look at the raw form data. You could do this with GetHTTPRequestData,
then reading the HTTP request body yourself. Yecch.
2. Rather than referencing the fields by name, use the elements array in
your CFSCRIPT block:
<cfscript>
for (var i = 0; i lt StructCount(Form); i = i + 1) {
WriteOutput("document.forms[0].elements[#i#].onclick =
EventHandler;");
}
</cfscript>
3. If you're setting the same event handler for all of the form fields, just
use JavaScript:
<script language="JavaScript">
for (field in document.forms[0]) {
field.onclick = EventHandler;
}
</script>
Dave Watts, CTO, Fig Leaf Software
http://www.figleaf.com/
voice: (202) 797-5496
fax: (202) 797-5444
______________________________________________________________________
Get the mailserver that powers this list at http://www.coolfusion.com
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists