Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combo box selected value retaining

Status
Not open for further replies.

Venkatachari

Programmer
Nov 20, 2000
9
IN
Dear All,

I am having 2 combo, combo1 and combo2
combo1 is loaded with city,
according to the selection of the city, state will be loaded.
i have written the code in onstatus event of city,
it is working fine
pl. check the code

Now the problem is since i am submiting the page, i am unable to retain the
selected value of the city. how could i acheive this?

<tr>
<th align=left ><font color=black>City</font></th>
<td>
<select name="cmbCity" onChange="javascript: CheckStatus('State'); submit();" > <!-- onChange= "javascript:alert(document.frmAddress1.cmbCity.value)" value="<%=request("cmbCity")%>" -->
<%
dim varCity
if cn.state = 1 then
cn.close
end if
Cn.open
if err.number <> 0 then
response.write err.description
response.end
end if
set Rs = server.createobject("Adodb.Recordset")
Rs.ActiveConnection = Cn
Rs.Cursortype = adOpenForwardOnly
Rs.CursorLocation = adUseClient
Rs.LockType = adLockOptimistic
Rs.Open "Select mCity_Name from mCity group by mCity_Name order by mCity_Name"
While not rs.eof
response.write "<option value = '" & rs.fields("mCity_Name") & "'>" & rs.fields("mCity_Name") & "</option>"
rs.movenext
wend
rs.close
Cn.Close
%>
</select>
</td>
</tr>
<tr>
<th align=left ><font color=black>State</font></th>
<td>
<select name="cmbState" value="<%=request("cmbState")%>" >
<%
dim varState
strSql = "Select mCity_State, mCity_Country from mCity where mCity_Name = '" & request("cmbCity") & "'"
varCity = request("cmbCity")
cn.open
set tmpRs = server.createObject("Adodb.Recordset")
tmpRs.ActiveConnection = Cn
tmpRs.CursorLocation = adUseClient
tmpRs.CursorType = adOpenDynamic
tmpRs.LockType = adLockOptimistic
tmprs.open strSql
varState=""
if not tmprs.eof then
varState = tmprs.fields("mCity_Country") & ""
end if
While not tmprs.eof
response.write "<option value = '" & tmprs.fields("mCity_State") & "'>" & tmprs.fields("mCity_State") & "</option>"
tmprs.movenext
wend
tmprs.close
set tmprs = nothing
cn.close
%>
</select>
</td>
</tr>
 
Code:
'keep the previous value of city
city = request("cmbCity") 


While not rs.eof
   if city = rs.fields("mCity_Name") then
     response.write  "<option value = '" & rs.fields("mCity_Name") & "' SELECTED>" & rs.fields("mCity_Name") & "</option>"
   
else

response.write "<option value = '" & rs.fields("mCity_Name") & "'>" & rs.fields("mCity_Name") & "</option>"

end if

        rs.movenext
         wend


Bastien

Cat, the other other white meat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top