Skip to main content
Participant
November 30, 2009
Question

How to show or hide form field based on query results

  • November 30, 2009
  • 1 reply
  • 392 views

I have a form with fields for country and state/province.  Initially, the state field is hidden.  When the user selects a country, I use a bind expression to get the states (if any) in the selected country.  I want to display the state field only if the country has states (since some countries don't).  Can someone tell me how to do this?  Here's the jquery script that initially hides the State field (and it's label) as well as the form fields:

<script>
    $(document).ready(function() {
        $('#stateID').hide();
        $('#stateIDLable').hide();
    });
</script>

Country:

<cfselect name="countryID" query="qryCountries" value="countryID" display="country" />

<div id="stateIDLable">State or Province:</div>
<cfselect id="stateID" name="stateID" bind="cfc:geography.getStates({countryID})" />

Thanks.

   PK

This topic has been closed for replies.

1 reply

ilssac
Inspiring
November 30, 2009

I presume you have a JavaScript function that handles the results of the cfc binding?

If you don't you will need to incorperate one.  Then, as well as populating the second select, this function can use logic to show the second set of controls.

Participant
November 30, 2009

Ian,  no I don't have a JavaScript function to handle the results of the cfc binding -- that's what I need help on.

:-)

PK