function writeSlt(arrstr,arrstrValue,selectedstr)
'arrstr 要顯示在option裡面的值,arrstrValue option的實際值,selectedstr要選取的預設值
'將一個字符串分割為數組,輸出select的option,並選取selectedstr arrstr&arrstrValue長度要一致
arr=split(arrstr,",")
arrValue=split(arrstrValue,",")
j=0
do while j<=ubound(arr)
if trim(arrValue(j))=trim(selectedstr) then
response.write "<option value='" & arrValue(j) & "' selected>" & arr(j) & "</option>"
else
response.write "<option value='" & arrValue(j) & "'>" & arr(j) & "</option>"
end if
j=j+1
loop
end function
可以從資料庫中讀出數據,形成逗開分隔的字串,來動態產生select的<option>
function getArrString(table,fld,cond,sortfld)
'取得指定表中指定欄位指字條件的數據,傳回一個以逗號分隔的字串
set rs=server.createobject("adodb.recordset")
sql="select " & fld & " from " & table
if len(cond)>0 then
sql=sql & " where " & cond
end if
if len(sortfld)>0 then
sql=sql & " order by " & sortfld
end if
rs.Open sql,conn,1,1
if not (rs.bof or rs.EOF) then
do while not rs.EOF
getArrString=getArrString & trim(rs(fld)) & ","
rs.MoveNext
loop
end if
getArrString=left(getArrString,len(getArrString)-1)
rs.Close
set rs=nothing
end function