2013-03-25 73 views
0

對不起連續工作也許問初學者問題&對不起我的英語,但我似乎無法得到這個工作(我沒有開發這個)。ColdFusion的條件選擇選項不會在IE9,Chrome和Firefox

我有ColdFusion中3個選擇下拉框。

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

它然後將選擇的值第二個下拉這是城市:

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

查詢來獲取狀態下的城市:

第一個下拉狀態由數據庫的onload填充
<!--- 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。

任何幫助將不勝感激。感謝ü

+0

你得到一個其他瀏覽器錯誤? – 2013-03-25 01:51:05

+1

還,我推薦使用'structKeyExists(URL,「PrevCityID」)',在你的if語句,並使用'選擇=「選擇」' – 2013-03-25 01:52:08

+0

待辦事項Firebug的或鍍鉻/ IE9相當於告訴你任何去除''## javascript錯誤? – 2013-03-25 03:06:00

回答

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

你在你的qCity查詢中缺少一個關閉'cfif'。 – 2013-03-25 15:58:33

+0

謝謝。更新。 – steve 2013-03-25 16:52:50