Coldfusion bindonLoad validate with two Text Fields?

ehart12
ehart12 used Ask the Experts™
on
I have CFFORM that is setup with two independent bindonLoad fields like shown below. Both fields validate data against a database query.

The first text field is called ITEM and the second text field is called GROUP.  I need to add extra validation in the query on the GROUP field.  I need to bring in the text entered from the ITEM field into the GROUP query.  I hope that makes sense...

I am not sure if ColdFusion will get me there, so I am open to other methods...


   Form:
         <form>
                 Item <input type="text" name="item" id="item">
                 <cfdiv bindonLoad="false" bind="url:checkItem.cfm?item={item@blur}">
                 Group <input type="text" name="group" id="group">
                 <cfdiv bindonLoad="false" bind="url:checkGroup.cfm?group={group@blur}">
                 Next field <input type="text" name="otherField">
         </form>

        checkItem.cfm:
         <cfparam name="url.item" default="">
         <cfquery name="findRecord" ...>
                 SELECT  Description
                 FROM   YourTable
                 WHERE  item = <cfqueryparam value="#url.item#" cfsqltype="cf_sql_varchar">
         </cfquery>


        checkGroup.cfm:
         <cfparam name="url.group" default="">
         <cfquery name="findRecord" ...>
                 SELECT  Description
                 FROM   YourTable
                 WHERE  group = #url.group#
                 AND      item = <somehow pulled from item field???>
         </cfquery>

Thank you,

Eric
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2015
Commented:
You can certainly bind multiple fields. But I don't think you can use @blur for both since it only fires for one field at a time.  So you could skip the query unless group is non-empty

   Form

   <cfdiv bindonLoad="false"
           bind="url:checkGroup.cfm?group={group@blur}&item={item@change}">


   checkGroup.cfm:
        <cfparam name="url.group" default="">
        <cfparam name="url.item" default="">

       <!--- if the value's non-empty, do validation --->
        <cfif len(trim(url.group))>
             <cfquery name="findRecord" ...>
                   SELECT  Description
                   FROM   YourTable
                   WHERE  group = #url.group#    <!--- don't forget cfqueryparam here --->
                   AND     item = <cfqueryparam value="#url.item#" cfsqltype="cf_sql_varchar">
             </cfquery>
             ...
        </cfif>

Author

Commented:
Worked great! Thank you...
Most Valuable Expert 2015

Commented:
So you could skip the query unless group is non-empty

I just remembered you could also use @none. Then the div refresh only triggers when leaving the group field:

<cfdiv bindonLoad="false"
           bind="url:checkGroup.cfm?group={group@blur}&item={item@none}">

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial