We help IT Professionals succeed at work.
Get Started

Start jquery dynamic selects with default values

Lee R Liddick Jr
on
478 Views
Last Modified: 2012-08-14
I'm using a bind to dynamically populate a drop down select box but I want the first values in the box that the user is presented with to be null/default.

Now, when the page loads, the first option appears in the 1st select so that automatically populates the 2nd select.  I want the first select to be null/default to no value.  I have tried a couple things and either the jquery doesn't work or I just get blank boxes.

<!--- my cfc --->
    <!--- Get array of facilities --->
    <cffunction name="getFacility" access="remote" returnType="array">
        <!--- Define variables --->
        <cfset var data="">
        <cfset var result=ArrayNew(2)>
        <cfset var i=0>

		<!--- Facility Query --->
        <CFQUERY NAME="data">
          select	a.fac_id, a.fac_nm 
          from	tbl_FAC a
          where	a.fac_id = #session.fac_id#
          </cfif>
        </CFQUERY>

        <!--- Convert results to array --->
        <cfloop index="i" from="1" to="#data.RecordCount#">
            <cfset result[i][1]=data.fac_id[i]>
            <cfset result[i][2]=data.fac_nm[i]>
        </cfloop>

        <!--- And return it --->
        <cfreturn result>
    </cffunction>

    <!--- Get surveys by facility --->
    <cffunction name="getSurvey" access="remote" returnType="array">
        <cfargument name="fac_id" type="numeric" required="no" default="9999">

        <!--- Define variables --->
        <cfset var data="">
        <cfset var result=ArrayNew(2)>
        <cfset var i=0>

<!--- Survey Query --->
<CFQUERY NAME="data">
  select	a.svy_id, a.svy_nm, a.hcf_id 
  from	tbl_survey a
  where	a.fac_id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.fac_id#">
</CFQUERY>

        <!--- Convert results to array --->
        <cfloop index="i" from="1" to="#data.RecordCount#">
            <cfset result[i][1]=data.svy_id[i]>
            <cfset result[i][2]=data.svy_nm[i]>
        </cfloop>

        <!--- And return it --->
        <cfreturn result>
    </cffunction>

<!--- here is my form on page1.cfm --->
<cfform>
<table>
    <tr>
        <td>Select Facility:</td>
        <td><cfselect name="fac_id"
                bind="cfc:myCFC.getFacility()"
                bindonload="true" /></td>
        <td>Select Survey:</td>
        <td><cfselect name="svy_id"
                bind="cfc:myCFC.getSurvey({fac_id})" /></td>
    </tr>
	<tr>
    	<td colspan="4" style="float:right;">
        	<cfinput name="varAction" CLASS="form_button_050" TYPE="button" VALUE="Run">
        </td>
    </tr>
</table>
</cfform>

Open in new window


So, how can I get the facility select to show 'Select Facility' and of course the survey select to be blank (at least until they select the facility)?
Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE