Personally I'd recommend neither ...

I doubt the cfswitch will save you any processing speed in this
particular case. However, I'd go for a function or custom tag to
handle your form elements and pass a structure to them to populate the
individual fields. Inside the tag, check the structure for the
appropriate key and use it if available to populate the field -- this
will cut down on your typing and improve consistency within the
application at the expense of a little processing time.

Matthew Walker produces a really nice form management tool that does
this ... I don't remember what he charges for it, but I'm sure he'd be
willing to discuss licensing for inclusion in other apps if you're
wanting to sell something.

Otherwise there's also the qForms _javascript_ API which is open-source
and pretty good in comparison to a lot of other OS projects that tend
to be tough to work with. http://www.pengoworks.com ... Once you've
got it installed in your app, then you can populate your whole form
with something like this:

<cfloop index="x" list="#qname.columnlist#">
<cfparam name="form.#x#" default="#qname[x][1]#"></cfloop>

<script type="_javascript_">
function temp() {
  <cfwddx action="" input="#form#" toplevelvariable="myValues">
  myForm = new qForm("myformname");
  myForm.setFields(myValues);
} window.> </script>

This cuts down all that cfif or cfswitch stuff... The onTap framework
now has a qForms library that makes this even easier, though I
scarcely see you plugging an existing app into the framework. :) In
any event, with the qForms library in an onTap application this whole
8 or so lines of code here can be condensed to one or two calls to a
UDF.

> I'm going over old code that has pre-filled form fields
> based on previous user entry.  Many are select boxes or
> radio groups with lots of options.  The current coding
> method is shown in Method 1 below.  The common way I see
> recommended to do this is in Method 2.  Before I rewrite
> this code, I thought I'd ask which y'all think is the
> better approach for a big form.

> Method 1 is verbose, but its use of cfswitch might be
> faster?

> Method 2 is easier to code, but uses slower cfifs.  Lots
> of them on longer forms.

> So on a form with a couple of dozen fields like this,
> which do you think is faster/a better approach?

> <!---METHOD 1--->
> <cfparam name="variables.LocalAA01" default=""
> type="string">
> <cfparam name="variables.LocalAA02" default=""
> type="string">
> <cfswitch _expression_="#QName.AA#">
> <cfcase value="A">
> <cfset variables.LocalAA01=" selected">
> </cfcase>
> <cfcase value="B">
> <cfset variables.LocalAA02=" selected">
> </cfcase>
> <cfdefaultcase>
> <cfset variables.LocalAA01=" selected">
> </cfdefaultcase>
> </cfswitch>
> <SELECT name="AA">
> <OPTION value="A"#variables.LocalAA01#>Choice A
> <OPTION value="B"#variables.LocalAA02#>Choice B
> </SELECT>

> <!---METHOD 2--->
> <SELECT name="AA">
> <OPTION value="A"<cfif not CompareNoCase(QName.AA,"A")>
> selected</cfif>>Choice A
> <OPTION value="B"<cfif not CompareNoCase(QName.AA,"B")>
> selected</cfif>>Choice B
> </SELECT>

> --
> -------------------------------------------
>  Matt Robertson,     [EMAIL PROTECTED]
>  MSB Designs, Inc. http://mysecretbase.com
> -------------------------------------------

> --
>
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to