Coldfusion条件选择选项在IE9,Chrome和Firefox中不起作用

时间:2013-03-25 01:46:56

标签: coldfusion

对不起,可能会问初学者问题&对不起我的英语,但我似乎无法完成这项工作(我没有开发这个)。

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

&GT;

最后显示要选择的城市

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

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

1 个答案:

答案 0 :(得分: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>