Click to See Complete Forum and Search --> : Drop Down List cannot work properly


wonder_gal
11-13-2005, 09:22 PM
have 2 drop down lists, it is coded such that second drop down list's content is loaded upon a selection from first drop down list. But here for my case i cannot see any value being loaded in my second drop down list after i have made a selection from first drop down list. Below is my code:

<html>
<body>
<form method="post" name = "frmUpdateMessage">

<%
Dim sLanguage
Dim dbConnection
Set dbConnection = Server.CreateObject("ADODB.Connection")
dbConnection.ConnectionString="Provider=SQLOLEDB.1;UID=sa;Password=password;Initi al Catalog=BMI;Data Source=(LOCAL)"
dbConnection.open
Response.write("Language Version: ")
If(Request("selLang") <> "") Then
sLanguage = Request("selLang")
End If
%>
<Select name = "selLang">
<option value="">Select a language</option>
<option value="English"<%if trim(sLanguage)= "English" then Response.Write "selected"%>>English</option>
<option value="Chinese"<%if trim(sLanguage)= "Chinese" then Response.Write "selected"%>>Chinese</option>
</Select>
<%
Response.write("<BR> BMI Category: ")
%>
<select name="selType" onchange="this.form.submit()">
<option value="">Select a category</option>
<%
Dim rs_Category,sSQL
set rs_Category = CreateObject("adodb.recordset")

If sLanguage = "English" Then
sSQL="SELECT * FROM outMessageENContent"
rs_Category.Open sSQL, dbConnection

sCategory = Request("selType")

While not rs_Category.EOF
%>
<option value="<%=rs_Category("msg_category")%>"<%if trim(request.form("selType"))= trim(rs_Category("msg_category")) then Response.Write "selected"%>><%=rs_Category("msg_category")%></option>
<%
rs_Category.MoveNext
Wend

rs_Category.Close
set rs_Category = nothing

ElseIf sLanguage = "Chinese" Then
sSQL="SELECT * FROM outMessageCHContent"
rs_Category.Open sSQL, dbConnection

sCategory = Request("selType")
While not rs_Category.EOF
%>
<option value="<%=rs_Category("msg_category")%>"<%if trim(request.form("selType"))= trim(rs_Category("msg_category")) then Response.Write "selected"%>><%=rs_Category("msg_category")%></option>
<%
rs_Category.MoveNext
Wend

rs_Category.Close
set rs_Category = nothing

End If
%>
</select>
<%
Dim sCategory
Dim sRisk
Dim sRemark

set rs=Server.CreateObject("ADODB.recordset")
rs.Open "SELECT * FROM outMessageENContent WHERE msg_category = '" & sCategory & "'", dbConnection

While not rs.EOF

sRisk = rs("msg_risk")
sRemark = rs("msg_remark")

Response.Write("<BR> Risk: <input type='text' name='txtRisk' size ='30' value='" & sRisk & "'>")
Response.Write("<BR>")
Response.Write("Remark: <input type='text' name='txtRemark' size ='120' value='" & sRemark & "'>")
Response.Write("<BR>")

rs.MoveNext
Wend

set rs = Nothing

dbConnection.Close()
Set dbConnection = Nothing
%>
<input type = "button" value = "Save" name = "btnSave" onClick = "pgUpdate()">
</form>
</body>
<script language="JavaScript" >
function pgUpdate()
{
document.frmUpdateMessage.action="UpdateMessage.asp"
document.frmUpdateMessage.submit()
}

</script>
</html>

Can anyone pls kindly point out to me what's the problem? Thanks alot.

zingmatter
11-14-2005, 09:36 AM
I might have missed it, but is the form being submitted after the selection is being made (ASP code happens at the server so any changes to the second list can only be done once the page is sent back to the server). You could use javascript (or even try AJAX) to get this working without having to reload the page.

Bullschmidt
11-14-2005, 06:34 PM
And this is how I do something like that. And perhaps it may hopefully give you some ideas. It's got a downloadable sample and does retain values after the post back (although it is admittedly somewhat complicated):

Classic ASP Design Tips - Dependent Listboxes
http://www.bullschmidt.com/devtip-dependentlistboxes.asp

zingmatter
11-15-2005, 05:03 AM
I haven't actually used it myself but AJAX (Asynchronous Javascript and XML) uses the ability of javascript to request from the server without having to reload the page. In effect this means that following say an onchange event in the dropdown list, the javascript can go back to the server and request a page on the server that can then send data back to the browser to fill the second list.

More info: http://en.wikipedia.org/wiki/AJAX

Using AJAX you can have updatable content without the need for a form reload. :)

In your code you need to have the onchange event in the selLang dropdown list which is sent back to the server to build the second list.

Hope this helps