Question : Trouble with the dependesnt select boxs

i am using cfselect to list all countries and in the furthur slect box it shows provices/towns and suburnsusing the bind attribute.

It works OK when i come to edit mode:

suppose i have already a country algeria in my database, so country is seelected algeria by default!

how do i load the other select values with the values from the database they have! Bydefault if nothing is there 0 is the default value in database! and suppose we have entered nothing in suburb and 0 will come from database so it will select the default one which is (select One)...

does not find an answer!

please guide

the code is below:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
<tr>
      <td align="right"><strong>Country&nbsp;:&nbsp;</strong></td>
      <td><select name="countryid" id="countryid" class="inputstyle">
      	<option value="none">(Select One)...</option>
		<cfoutput query="getcountries">
      		<option value="#countryid#" <cfif getcountries.countryid EQ countryid>selected="selected"</cfif>>#country#</option>
		</cfoutput>
		</select>
		</td>
    </tr>
	<tr>
      <td align="right"><strong>Province&nbsp;:&nbsp;</strong></td>
      <td><cfselect name="province" bind="cfc:com.remoteCalls.getRemoteProvince({countryid})" bindonload="false" class="inputstyle"><option value="0" selected>Select One</option></cfselect></td>
    </tr>
	<tr>
      <td align="right"><strong>Town&nbsp;:&nbsp;</strong></td>
      <td><cfselect name="town" id="town" class="inputstyle" bind="cfc:com.remoteCalls.getRemoteTowns({province})" bindonload="false"><option value="0" selected>Select One</option></cfselect></td>
    </tr>
    <tr>
      <td align="right"><strong>Suburb&nbsp;:&nbsp;</strong></td>
      <td><cfselect name="suburb" id="suburb" class="inputstyle" bind="cfc:com.remoteCalls.getRemoteSuburb({town})" bindonload="false"><option value="0" selected>Select One</option></cfselect></td>
    </tr>

Answer : Trouble with the dependesnt select boxs

AFAIK, there's really no "great" solution for this.  A workable hack is to *keep* the bind's in place, but populate the initial values manually.  So the lists will show the correct default values initially, but will still be linked.

Use cfinvoke to get the initial data for each list
       
       <!--- change the parameter names if needed ...--->
      <cfinvoke component="com.remoteCalls" method="getRemoteProvince"  
                      countryId="#countryid#"
                      returnVariable="getProvinces"
          >
       ... run other methods ....

Then use the results to populate each cfselect manually. Again, *don't* remove the bind's or the lists won't be linked properly.

<cfselect name="province" bind="cfc:com.remoteCalls.getRemoteProvince({countryid})" ... etc....>
        <option value="0" selected>Select One</option>
       <cfoutput>
       <cfloop array="#getProvinces#" index="row">
      <option value="#row[1]#" <cfif row[1] eq provinceId>selected="selected"</cfif>>#row[2]#</option>
         </cfloop>
       </cfoutput>
</cfselect>

       ... populate other lists ....


BTW: Binds are great for "add new" forms, but lousy for "edit" forms IMHO.  Especially when you have a lot of related selects.  What you're trying to do is simulate the onchange event for each cfselect list.  That's easy enough.  But to get the desired results, you have trigger them in a *specific*order (ie synchronous) Otherwise, the lists won't contain the right items.  

Also, CF8 binds don't support "selected". So even if you figured out how to populate each list with the desired items, you can't easily preselect one of the items! It's a pain, but it's a known limitation of in CF8.
Random Solutions  
 
programming4us programming4us