• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 462
  • Last Modified:

Start jquery dynamic selects with default values

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)?
0
Lee R Liddick Jr
Asked:
Lee R Liddick Jr
1 Solution
 
ansudhindraCommented:
Replace the loop code in your getFacility function with the below code

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

Open in new window

0
 
Lee R Liddick JrReporting AnalystAuthor Commented:
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now