0

I have three select boxes: State, District, School. The first two work great if I don't have the school, but the school is actually the important part. Without the school select everything works fine. With the school box I get the error:

Bind failed, element not found: pid

CFC

<cfcomponent>
    <cfset THIS.dsn="whatever">

    <cffunction name="getDistricts" access="remote" returntype="query">
        <cfargument name="state" required="yes" hint="The districts are in this state." />
        <cfstoredproc datasource="#THIS.dsn#" procedure="getSchoolAndDistrict" returncode="yes">
            <cfprocparam cfsqltype="cf_sql_varchar" dbvarname="@mstate" value="#arguments.state#" type="in">
            <cfprocresult resultset="1" name="districts">
        </cfstoredproc>
        <cfreturn districts>
    </cffunction>


    <cffunction name="getSchools" access="remote" returntype="query">
        <cfargument name="state" required="yes" hint="The districts are in this state." />
        <cfargument name="pid" required="yes" hint="The district pid." />
        <cfstoredproc datasource="#THIS.dsn#" procedure="getSchoolAndDistrict" returncode="yes">
            <cfprocparam cfsqltype="cf_sql_varchar" dbvarname="@mstate" value="#arguments.state#" type="in">
            <cfprocparam cfsqltype="cf_sql_varchar" dbvarname="@pid" value="#arguments.pid#" type="in">
            <cfprocresult resultset="2" name="schools">
        </cfstoredproc>
        <cfreturn schools>
    </cffunction>

</cfcomponent>

CFM

<cfoutput>
<cfform action="#CGI.PATH_INFO#" name="testdistricts" method="post">

    <cfselect name="states" query="states" 
         queryPosition="below"  
         display="state" value="state">
        <option value="">State</option>
    </cfselect>
    &nbsp;
    <cfselect name="districts" 
         bind="cfc:cfcs.getDistricts.getDistricts({states})" 
         queryPosition="below" 
         display="name" value="pid" bindonload="no">
        <option value="">District</option></cfselect>
    &nbsp;
    <cfselect name="schools" 
          bind="cfc:cfcs.getDistricts.getSchools({pid})" 
          queryPosition="below" 
          display="name" value="pid" bindonload="no">

        <option value="">School</option>
    </cfselect>
    <br> <br>

    <cfinput type="submit" name="submit" value="Submit">
</cfform>
</cfoutput>
Leigh
  • 28,765
  • 10
  • 55
  • 103
  • 1
    What is your interpetation of the error message, "Bind failed, element not found: pid"? – Dan Bracuk Jul 24 '14 at 14:56
  • To start, your getSchools function needs two arguments but you are only attempting to send it one. Next, you have to use another form element in your bind, and you don't have one named pid. There might be some other issues, but you have to solve those two first. – Dan Bracuk Jul 24 '14 at 15:03
  • 4
    Because `cfselect`. Don't use the built in UI components of ColdFusion, they are abysmal. Learn how to do this the correct way using a library like jQuery - or JavaScript 'MVC' framework like Angular or Knockout. – Scott Stroz Jul 24 '14 at 16:00
  • 1
    Nothing to do with your question, but ... fyi `dbvarname` is deprecated and does not actually work, so be sure you are using [positional notation](http://stackoverflow.com/questions/14507184/different-results-with-cfstoredproc-and-cfquery/14508475#14508475). Also, though I agree about avoiding the CF UI stuff, you do not actually need to wrap the `cfform` in `cfoutput`. Usually, variables inside a CF tag are evaluated automatically - without any extra output tags. – Leigh Jul 24 '14 at 18:51
  • Thanks to all of you. You are also all correct in that I shouldn't have used CF, but I thought I might because I'm maintaining a CF-built set of applications and only adding whatever is demanded. And I know that's a dead-end path. I'm working on learning PHP/MySQL/Drupal and adding jquery to my toolbox, but I can't apply that at work because the servers available to me aren't set to run PHP. Thank you very much. –  Jul 25 '14 at 17:41

1 Answers1

0

Your problem is that the Schools select is bound to the value of the selected option instead of being bound to the district control itself...

    <cfform action="#CGI.PATH_INFO#" name="testdistricts" method="post">

    <cfselect name="states" query="states" 
         queryPosition="below"  
         display="state" value="state">
        <option value="">State</option>
    </cfselect>
    &nbsp;
    <cfselect name="districts" 
         bind="cfc:cfcs.getDistricts.getDistricts({states})" 
         queryPosition="below" 
         display="name" value="pid" bindonload="no">
        <option value="">District</option></cfselect>
    &nbsp;
    <cfselect name="schools" 
          bind="cfc:cfcs.getDistricts.getSchools({districts})" 
          queryPosition="below" 
          display="name" value="pid" bindonload="no">

        <option value="">School</option>
    </cfselect>
    <br> <br>

    <cfinput type="submit" name="submit" value="Submit">
</cfform>

This is where your problem is

bind="cfc:cfcs.getDistricts.getSchools({districts})" 
RealSollyM
  • 1,530
  • 1
  • 22
  • 35