| | |
populating a listbox from another listbox dynamically??
Please support our ASP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
hello,
i have two dropdown listboxes: one is for the countries, the other one's for the areas. in the 'countries' listbox, the user can select multiple values. what he selects, the second listbox is going to display the country's/-tries' corresponding areas. all entries should be fetched from the database.
ex. if the user selects u.k. and philippines from the countries listbox, the areas listbox will automatically display all areas from these two countries, i.e. take note, taken from the database. btw, i think it'll need javascript too. :eek:
i hope you got what i mean and could help me, once again :o , with this problem. i really need it very badly and ASAP. :cry:
thank u in advance! happy new year!!
i have two dropdown listboxes: one is for the countries, the other one's for the areas. in the 'countries' listbox, the user can select multiple values. what he selects, the second listbox is going to display the country's/-tries' corresponding areas. all entries should be fetched from the database.
ex. if the user selects u.k. and philippines from the countries listbox, the areas listbox will automatically display all areas from these two countries, i.e. take note, taken from the database. btw, i think it'll need javascript too. :eek:
i hope you got what i mean and could help me, once again :o , with this problem. i really need it very badly and ASAP. :cry:
thank u in advance! happy new year!!
•
•
Join Date: Feb 2006
Posts: 1
Reputation:
Solved Threads: 0
<html dir="rtl">
<head>
<script language="javascript">
function section_onchange()
{
DEPARTMENTS = document.form1.DEPARTMENTS.options[document.form1.DEPARTMENTS.selectedIndex].value;
window.location.href = "list.asp?DEPT_ID=" + DEPARTMENTS
}
</script>
</head>
<%
DEPT_ID= request("DEPT_ID")
%>
<form method="POST" name=form1>
<table dir=ltr>
<tr>
<td bgcolor="#E7EFF7" width="29%" class="bodytxt">
Depts</td>
<td bgcolor="#E7EFF7" width="69%" class="bodytxt">
<%'------------------------------------ This select to select DEPARTMENTS -------------------------------%><select size="4" name="DEPARTMENTS" class=bord3333 dir="rtl" onchange="return section_onchange();" multiple>
<option>-------------- CHOOSE DEPT----------------</option>
<%
Set Conn = server.createobject("adodb.connection")
Conn.open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=diwan;Data Source=10.35.12.20"
set rs1 = server.createobject("adodb.recordset")
sql = "select * from departments"
rs1.open sql,conn
if not rs1.eof then
while not rs1.eof
%>
<option value="<%=rs1("DEPT_ID")%>" <% if trim(DEPT_ID)= trim(rs1("DEPT_ID")) then %> selected <%end if%> >
<%=rs1("DEPT_NAME")%> </option>
<%
rs1.movenext
wend
rs1.close
set rs1 = nothing
' RESPONSE.WRITE SQL
'response.end
end if
%>
</select>
</td>
</tr>
<%'------------------------------------ This select to select city by DEPARTMENTS Id -------------------------------%>
<% if DEPT_ID <> "" then%>
<tr>
<td bgcolor="#E7EFF7" width="29%" class="bodytxt">
Subjects</td>
<td bgcolor="#E7EFF7" width="69%" class="bodytxt">
<select size="1" name="city" dir="rtl" class=bord3333>
<%
Set Conn = server.createobject("adodb.connection")
Conn.open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=diwan;Data Source=10.35.12.20"
set rs = server.createobject("adodb.recordset")
sql = "select * from SUBJECT where DEPT_ID= " & DEPT_ID
'reponse.write sql
rs.open sql,conn
if not rs.eof then
while not rs.eof
%>
<option value="<%=rs("subject_id")%>" <% if trim(subject_desc)= trim(rs("subject_desc")) then %> selected <%end if%> >
<%=rs("subject_desc")%> </option>
<%
rs.movenext
wend
rs.close
set rs = nothing
end if
%>
</select>
<%end if%><%'------------------------------------------------- End City select -----------------------------------------------------%>
</td>
</tr>
</table>
</form>
<head>
<script language="javascript">
function section_onchange()
{
DEPARTMENTS = document.form1.DEPARTMENTS.options[document.form1.DEPARTMENTS.selectedIndex].value;
window.location.href = "list.asp?DEPT_ID=" + DEPARTMENTS
}
</script>
</head>
<%
DEPT_ID= request("DEPT_ID")
%>
<form method="POST" name=form1>
<table dir=ltr>
<tr>
<td bgcolor="#E7EFF7" width="29%" class="bodytxt">
Depts</td>
<td bgcolor="#E7EFF7" width="69%" class="bodytxt">
<%'------------------------------------ This select to select DEPARTMENTS -------------------------------%><select size="4" name="DEPARTMENTS" class=bord3333 dir="rtl" onchange="return section_onchange();" multiple>
<option>-------------- CHOOSE DEPT----------------</option>
<%
Set Conn = server.createobject("adodb.connection")
Conn.open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=diwan;Data Source=10.35.12.20"
set rs1 = server.createobject("adodb.recordset")
sql = "select * from departments"
rs1.open sql,conn
if not rs1.eof then
while not rs1.eof
%>
<option value="<%=rs1("DEPT_ID")%>" <% if trim(DEPT_ID)= trim(rs1("DEPT_ID")) then %> selected <%end if%> >
<%=rs1("DEPT_NAME")%> </option>
<%
rs1.movenext
wend
rs1.close
set rs1 = nothing
' RESPONSE.WRITE SQL
'response.end
end if
%>
</select>
</td>
</tr>
<%'------------------------------------ This select to select city by DEPARTMENTS Id -------------------------------%>
<% if DEPT_ID <> "" then%>
<tr>
<td bgcolor="#E7EFF7" width="29%" class="bodytxt">
Subjects</td>
<td bgcolor="#E7EFF7" width="69%" class="bodytxt">
<select size="1" name="city" dir="rtl" class=bord3333>
<%
Set Conn = server.createobject("adodb.connection")
Conn.open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=diwan;Data Source=10.35.12.20"
set rs = server.createobject("adodb.recordset")
sql = "select * from SUBJECT where DEPT_ID= " & DEPT_ID
'reponse.write sql
rs.open sql,conn
if not rs.eof then
while not rs.eof
%>
<option value="<%=rs("subject_id")%>" <% if trim(subject_desc)= trim(rs("subject_desc")) then %> selected <%end if%> >
<%=rs("subject_desc")%> </option>
<%
rs.movenext
wend
rs.close
set rs = nothing
end if
%>
</select>
<%end if%><%'------------------------------------------------- End City select -----------------------------------------------------%>
</td>
</tr>
</table>
</form>
![]() |
Similar Threads
- getting data from a list box. (Visual Basic 4 / 5 / 6)
- Listbox help needed!! (VB.NET)
- Looping through listbox items (JavaScript / DHTML / AJAX)
- Listbox selectedItem.value cannot be retrieved (ASP.NET)
- Listbox with Columns (Visual Basic 4 / 5 / 6)
- Adding Totals from Listbox DB (DAO) (Visual Basic 4 / 5 / 6)
- Populating & Retrieving Data in a listbox : ASP.NET (w/ VB.NET) (ASP.NET)
Other Threads in the ASP Forum
- Previous Thread: need help, to Search from database
- Next Thread: gulam soofi a learning web developer.
| Thread Tools | Search this Thread |
Tag cloud for ASP
archive asp asp.net aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection calendar changeable connection current database databaseconnection diagnostics dreamweaver excel fso html iis microsoft msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile record searchbox selectoption server single specfic sqlserver sqlserverconnection toolkit web webserver windows7





