I have two dropdown boxes linked with a table of Microsoft Access. After I choose one of the options in the first the second listbox should change. The thing is that I have different queries from the database. What can I do or any examples about that??
i'm not quite sure what you're trying to do... are you trying to give completely different options in the second drop down depending upon what is selected in the first? or are you just try to change the selected index of the second depending upon what is selected in the first...
both can be done with javascript. but, it would be easier to help you if we knew which you wanted and explained a little more.
for the the latter, this is very easy, but, for the former, it would require you to build arrays with your data from the quiry, then populate the select box with the correct array depending upon the selection. adam@aauser.com
I'm trying to give completely different options in the second drop down box depending upon what is selected in the first.
I have done part of code, but don't know what's wrong with the code, it can't display any option in the second box, would you help me to check it, please?
<table width="100%" border="0" align="left">
<tr><td colspan="2">
<form name="partslocator">
<table border="0" cellspacing="0" cellpadding="0">
<tr><td>
<b>Step 1.</b>
</td>
<td>
<select name="model" size="1" onChange="redirect(this.options.selectedIndex);">
<option selected> Select Category Type </option>
<%
myconn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & server.mappath("NewsData.mdb" & ";"
myquery="select distinct Category from Category"
dim conntemp, rstemp
set conntemp=server.createobject("adodb.connection"
conntemp.open myconn
set rstemp=conntemp.execute(myquery)
do while not rstemp.eof
fieldfirst=RStemp(0)
if isnull(fieldfirst) or fieldfirst="" then
' ignore
else
response.write "<option value='" & fieldfirst
response.write "'>" & fieldfirst & "</option>"
end if
rstemp.movenext
loop
%>
</select>
<%
rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing
%>
</td></tr>
<tr><td>
<b>Step 2.</b>
</td>
<td>
<select name="availablemodels" size="1">
<option value="#" selected> Select the Category first </option>
</select></td></tr></table></form>
<script>
var groups=document.partslocator.model.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group=new Array()
group[0][0]=new Option("Select Model"
<%
myconn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & server.mappath("NewsData.mdb" & ";"
myquery="select MICode from Category where Category='" &model& "'"
dim conntemp1, rstemp1
set conntemp1=server.createobject("adodb.connection"
conntemp1.open myconn
set rstemp1=conntemp1.execute(myquery)
j=1
do while not rstemp1.eof
k=0
MICode=RStemp1("MICode"
%>
group[<%=j%>][<%=k%>]=new Option("<%=MICode%>"
<%
j=j+1
rstemp1.MoveNext
loop
rstemp1.close
%>
var temp=document.partslocator.availablemodels
function redirect(x)
{
for (m=temp.options.length-1; m>0; m--)
temp.options[m]=null
for (i=0; i<group[x].length; i++)
{
temp.options=new Option(group[x].text,group[x].value)
}
temp.options[0].selected=true
}
</script>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.