0

很抱歉可能会问初学者问题并且对我的英语感到抱歉,但我似乎无法完成这项工作(我没有开发这个)。

我在 Coldfusion 中有 3 个选择下拉框。第一个下拉状态由数据库 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>

然后它将选定的值传递给第二个下拉列表,即 City:

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

查询获取州下的城市:

<!--- 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

>

最后显示要选择的城市

<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>

问题是这仅适用于 IE6、7 和 8。它不适用于 Chrome、IE 9 及更高版本和 firefox。

任何帮助将非常感激。感谢你

4

1 回答 1

0

我添加了标签以防止 SQL 注入,并删除了包含 ## 的额外标签。您不需要它们,而是 cfif 语句。

此外,在州区域,你有一个看起来有点奇怪的循环。似乎您只有一个选择下拉框,因此它只有 1 个变量,但是,您正在循环遍历它,就好像它有多个并取第二个值一样。我不明白这一点,并且觉得您的代码在该位置可能出错了。

我建议将您的代码更改为以下内容:

 <!--- 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>

然后你的下一个文件:

<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

最后

<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>
于 2013-03-25T02:15:08.543 回答