台灣最大程式設計社群網站
線上人數
699
 
會員總數:245782
討論主題:189420
歡迎您免費加入會員
討論區列表 >> AJAX / JSON / jQuery >> 有關三階動態選單傳值問題
[]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
有關三階動態選單傳值問題
價值 : 10 QP  點閱數:2249 回應數:2
樓主

danielfu
初學者
54 51
574 70
發送站內信

我想做一個選擇縣市的的三階動態選單,程式碼片段如下

<incFunctionCommon.asp>
Function LocationCity()

Set sRS = cnnCampus.Execute("Select CodeNo,CodeNameA From tCodeCityM Where CodeType = 1")
If Not sRS.Eof Then
arrCity = sRS.GetRows()
CityCount = UBound(arrCity,2)
Else
CityCount = -1
End If
sRS.Close
Set sRS = Nothing

Response.Write "<select name=""Area"" onchange=""sltCity(2,this.value,'DivCityA')"">" & _
"<option value="""">請選擇</option>"
For ci = 0 To CityCount
If Int(tCityA) = Int(arrCity(0,ci)) Or Int(tCity/10000) = Int(arrCity(0,ci)/10000) Then
Response.Write "<option value=""" & arrCity(0,ci) & """ selected>" & arrCity(1,ci) & "</option>"
Else
Response.Write "<option value=""" & arrCity(0,ci) & """>" & arrCity(1,ci) & "</option>"
End If
Next
Response.Write "</select> "

Response.Write "<span id=""DivCityA"">"
Response.Write "<select name=""city"" onchange="""">"
Response.Write "<option value="""">請選擇</option>"
Response.Write "</select>"
Response.Write "</span>"

Response.Write "<span id=""DivCityB"">"
Response.Write "<select name=""city"" onchange="""">"
Response.Write "<option value="""">請選擇</option>"
Response.Write "</select>"
Response.Write "</span>"


Response.Write "<span id=""DivCityC"">"
Response.Write "</span>"


End Function



<incFunctionCommon.js>
function sltCity(tp,value,divName)
{
//alert(tp);
//alert(value);

//tg='DivCityA'
ajax = new ActiveXObject("Msxml2.XMLHTTP");

if (!(document.getElementById(divName)))
{
alert('ee');
}


ajax.onReadyStateChange=function()
{
if (ajax.readyState==4)
if (ajax.status==200)
document.getElementById(divName).innerHTML = ajax.responseText;
else
alert ("伺服器發生錯誤,無法回傳資料!");
}


url='/includes/incGetCityCode.asp?tp='+tp+'&value='+value+'&divName='+divName;

ajax.open("GET", url, true); // 設定 ajax 物件的參數
ajax.send(""); // 執行 ajax

}

function sltCity1(tp,value,divName)
{

alert(tp+','+value+','+divName);

}

<incGetCityCode.asp>
<%

dim tp,value

tp=request.querystring("tp")
value=request.querystring("value")
dn=request.querystring("divName")



if tp=2 then
sql="Select CodeNo,CodeNameA From tCodeCityM Where CodeType =2 and CodeNo/10000="&int(value/10000)
elseif tp=3 then
sql="Select CodeNo,CodeNameA From tCodeCityM Where CodeType =3 and CodeNo/100="&int(value/100)
else

end if

'response.write "sql="

Set sRS = cnnCampus.Execute(sql)
If Not sRS.Eof Then
arrCity = sRS.GetRows()
CityCount = UBound(arrCity,2)
Else
CityCount = -1
End If
sRS.Close
Set sRS = Nothing
%>
<select size="1" name="city" onchange="sltCity1(2,this.value,'DivCityB')">
<option value="">請選擇</option>
<%if isarray(arrCity) then%>
<%for ci=0 to CityCount%>
<option <%=arrCity(0,ci)%>><%=arrCity(1,ci)%></option>
<%next%>
<%end if%>
</select>

=========================================================================================
當我選擇了Area這個下拉選單後,sltCity這函數會將<div id=divCityA></div>的內容置換為incGetCityCode.asp的查詢結果,
但在第二層選單時,卻無法抓取到選單的值,也就是sltCity1第二個參數是空值,請問要如何才能取得第二層選單的option value呢?(可以取得selectedindex)

搜尋相關Tags的文章: [ 三階選單 ] ,
本篇文章發表於2010-06-07 14:51
1樓
作者回應

danielfu
檢舉此回應
原來是我<option>的地方忘了指令value值
本篇文章回覆於2010-06-07 16:52
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
2樓
回應

topcat
捐贈 VP 給 topcat 檢舉此回應
這個參考看看
http://www.blueshop.com.tw/download/show.asp?pgmcde=PGM20060622171613PLZ
本篇文章回覆於2010-06-07 16:57
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
   
1

回覆
如要回應,請先登入.