Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

populating a drop down based on another

I'm using the following code to populate the second combo after the selection of first combo. But when the page refreshes after the selection of first combo value, it don't save its value. So as a result, it always shows the first value of DB and its results in the second combo.
Here is the code :


function doSubmit()
{
document.fSelect.action = "combo.asp"
document.fSelect.method ="post"
document.fSelect.submit();
}




<%
set con = Server.CreateObject("ADODB.Connection")
set Rs = Server.CreateObject("ADODB.Recordset")

Con.Open strConnect

SQL = "Select * FROM City"
Rs.Open SQL, Con, 1, 2
%>

city


<% While Not Rs.EOF %>
><% =Rs.Fields("City")%>
<%

Rs.MoveNext
Wend

%>

<%
'response.write (Session.value("val"))
If Request.Form("City") > 0 Then

strSQl= "select * from Towns where SNo=SNo"
Rs.close
Rs.open strsql, con

End If

%>

town

<% If Rs.RecordCount > 0 Then
While Not Rs.EOF %>
><% =Rs.Fields("Towns")%>
<% Rs.Movenext
Wend
End if
%>

 



Comments

  • raylouwraylouw Member Posts: 30
    : I'm using the following code to populate the second combo after the selection of first combo. But when the page refreshes after the selection of first combo value, it don't save its value. So as a result, it always shows the first value of DB and its results in the second combo.
    : Here is the code :
    :
    :
    : function doSubmit()
    : {
    : document.fSelect.action = "combo.asp"
    : document.fSelect.method ="post"
    : document.fSelect.submit();
    : }
    :
    :

    You could do this the hard way, with tones of code, or you could use an asp dropdow and enable ViewState for the page. This will make the drop down "remember" the last value selected.
    :
    :
    : <%
    : set con = Server.CreateObject("ADODB.Connection")
    : set Rs = Server.CreateObject("ADODB.Recordset")
    :
    : Con.Open strConnect
    :
    : SQL = "Select * FROM City"
    : Rs.Open SQL, Con, 1, 2
    : %>
    :
    :

    city
    :
    :
    : <% While Not Rs.EOF %>
    : ><% =Rs.Fields("City")%>
    : <%
    :
    : Rs.MoveNext
    : Wend
    :
    : %>
    :
    :

    : <%
    : 'response.write (Session.value("val"))
    : If Request.Form("City") > 0 Then
    :
    : strSQl= "select * from Towns where SNo=SNo"
    : Rs.close
    : Rs.open strsql, con
    :
    : End If
    :
    : %>
    :
    :

    town
    :
    : <% If Rs.RecordCount > 0 Then
    : While Not Rs.EOF %>
    : ><% =Rs.Fields("Towns")%>
    : <% Rs.Movenext
    : Wend
    : End if
    : %>
    :
    :

    :

     

    :
    :
    :
    :

Sign In or Register to comment.