0

Sorry for maybe asking beginners questions & sorry for my English, but I cant seem to get this work (I didn't develop this).

I have 3 select dropdown boxes in Coldfusion. The first dropdown State is populated by a database onload:

 <cfquery name="qState" datasource="#Variables.fw.Config.DSN#">
    SELECT * from refState WHERE State = '#url.BindID#' AND status = 'Active' order by ldesc
</cfquery>

<select name="State">
                <option value="" <cfif isDefined("url.PrevID") and #url.PrevID# EQ "">selected</cfif>></option>
                <cfoutput query="qState">
                    <option value="#qState.State#" <cfif isDefined("url.PrevID") and #url.PrevID# EQ #qState.State#>selected</cfif>>#qState.Ldesc#</option>
                </cfoutput>
            </select>

It then passes the selected value to the second dropdown which is City:

<cfdiv id="City" bind="url:index.cfm?section=public&action=City&txtReff=#txtReff#&BindStateID={State}&PrevCityID=#txtCity#">

Query to get city under the state:

<!--- loop to fix the state, returns the correct value even though i hav limited knowledge on this --->
    <cfset num = 0>
    <cfloop index="i" list="#url.BindStateID#" delimiters=",">
        <cfset num = #num# + 1>
        <cfif #num# EQ 2>
            <cfset p = #i#>
        </cfif>
    </cfloop>

<!--- then the query to get cities under the state --->
    <cfquery name="qCity" datasource="#Variables.fw.Config.DSN#">
        SELECT * from refCity WHERE State = '#p#' AND status = 'Active' order by ldesc
    </cfquery

>

And finally displays the city to select

<select name="City">
                <option value="" <cfif isDefined("url.PrevCityID") and #url.PrevCityID# EQ "">selected</cfif>></option>
                <cfoutput query="qCity">
       <option value="#qCity.City#" <cfif isDefined("url.PrevCityID") and #url.PrevCityID# EQ #qCity.City#>selected</cfif>>#qCity.Ldesc#</option>

                </cfoutput>
            </select>

The problem is this only works for IE6, 7 and 8. It does not work on Chrome, IE 9 and above and firefox.

Any help would be much appreciated. Thank u

1 Answers1

0

I added tags to protect against SQL injection and I removed extra tags that contained ##. You don't need them instead cfif statements.

Also, in the state area, you had a loop that looked kind of strange. it appears that you only have a single select drop down box, so it would only have 1 variable, however, you were looping through it as if it had more than one and taking a second value. I didnt understand that and felt your code is probably going wrong at that location.

I would suggest altering your code to the following:

 <!--- Personal Preference --->
 <cfparam name="url.prefid" default="">

 <cfquery name="qState" datasource="#Variables.fw.Config.DSN#">
    SELECT * from refState 
    WHERE State = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.BindID#">
          AND status = 'Active' 
    order by ldesc
</cfquery>

<select name="State" id="State">
    <option value="" <cfif trim(url.PrevID) eq "">selected</cfif>></option>
    <cfoutput query="qState">
      <option value="#qState.State#" <cfif trim(url.previd) eq qState.State>selected</cfif>>#qState.Ldesc#</option>
    </cfoutput>
</select>

And then your next file:

<cfparam name="url.bindstateid" default="">

<!--- then the query to get cities under the state --->
    <cfquery name="qCity" datasource="#Variables.fw.Config.DSN#">
        SELECT * 
        from refCity 
        WHERE 1=0 
        <cfif trim(url.bindstateid) is not "">
        OR (State = <cfqueryparam cfsqltype="cf_sql_varchar" value="#url.bindstateid#"> AND status = 'Active')
        </cfif>
        order by ldesc
    </cfquery

and last

<cfparam name="url.prevcityid" default="">

<select name="City">
    <option value="" <cfif trim(url.prevCityid) eq "">selected</cfif>></option>
    <cfoutput query="qCity">
        <option value="#qCity.City#" <cfif trim(url.PrevCityID) is "">selected</cfif>>#qCity.Ldesc#</option>
    </cfoutput>
</select>
steve
  • 1,490
  • 10
  • 18