Two tables, one is ecom_manufacturer, one is ecom_model.
ecom_manufacturer table.
mfr_id, mfr_name
ecom_model table
model_id, model_name, mfr_id
I'm able to populate the first drop down with the manufacturer names. But I'm having trouble populating the second (models) based on which manufacturer is selected in the first. I know this is a typical problem, but I haven't been able to find a solution that fits my needs.
If anyone could take a look at my code and let me know what I'm doing wrong I'd appreciate it. Here's the code
Thanks!
ecom_manufacturer table.
mfr_id, mfr_name
ecom_model table
model_id, model_name, mfr_id
I'm able to populate the first drop down with the manufacturer names. But I'm having trouble populating the second (models) based on which manufacturer is selected in the first. I know this is a typical problem, but I haven't been able to find a solution that fits my needs.
If anyone could take a look at my code and let me know what I'm doing wrong I'd appreciate it. Here's the code
Code:
<!--#include file="includes/_variables.inc" -->
<%Response.Buffer = true%>
<HTML>
<HEAD>
<script language = "JavaScript">
function subcat()
cat = document.subad.catagory[document.subad.catagory.selectedIndex].value;
url = "submitad.asp?cat="
url = url + cat;
window.location.href< = url;
function sublist(inform, selecteditem)
inform.subcatagory.length = 0
<%
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = strServerConnection
rs.Source = "select * from ecom_model where mfr_id =" %> & cat
<% rs.Open()
x=0
count= 0
y=0
do while not rs.eof
%>
x = <%= trim(y) %>
subcat = new Array();
subcatagorys = "<%= trim(rs("model_name"))%>"
subcatagoryof = "<%= trim(rs("mfr_id"))%>"
subcatagoryid = "<%= trim(rs("model_id"))%>"
subcat[x,0] = subcatagorys;
subcat[x,1] = subcatagoryof;
subcat[x,2] = subcatagoryid;
if (subcat[x,1] == selecteditem)
{
var option<%= trim(count) %> = new Option(subcat[x,0], subcat[x,2])
inform.subcatagory.options[inform.subcatagory.length]=option <%= trim(count)%>
<%
count = count + 1
y = y + 1
rs.movenext
loop
%>
</script>
<title>Submit an Ad</title>
<LINK rel="stylesheet" type="text/css" href="style/summary.css">
</HEAD>
<BODY onLoad = "sublist(document.subad,document.subad.catagory[document.subad.catagory.selectedIndex].value)">
<form name = subad action = "" >
<table>
<tr>
<td>Headline</td>
</tr>
<tr>
<td><Input Name = "headline" MaxLength = "100" value="" size=50></td>
</tr>
<tr>
<td>Description</td>
</tr>
<tr>
<td><textarea name = "description" rows = 5 cols = 50></textarea></td>
</tr>
<%
cat = Request.QueryString("cat")
Set rs = Server.CreateObject("ADODB.Recordset")
rs.ActiveConnection = strServerConnection
rs.Source = "SELECT * from ecom_manufacturer"
rs.Open()
%>
<tr>
<td>Catagory</td>
</tr>
<tr>
<td><SELECT id=catagory name=catagory onChange = "sublist(this.form, document.subad.catagory[document.subad.catagory.selectedIndex].value)">
<OPTION selected value=""></OPTION>
<%
do until rs.eof
%>
<OPTION value="<%= rs("mfr_id")%>"><% = rs("mfr_name")%></OPTION>
<%
rs.movenext
loop
set rs = nothing
%>
</SELECT></td>
</tr>
<tr>
<td><SELECT id = "subcatagory" name="subcatagory">
<Option selected value="none">-------------------------</option>
</SELECT>
</td>
</tr>
<tr>
<td>Price</td>
<tr>
<tr>
<td><INPUT type="text" id=price name=price></td>
</tr>
<td><Input type=submit value = "Submit" id=submit1 name=submit1 ></td>
</tr>
</table >
</form>
<%
'Else
'Response.Redirect url
'End if
%>
</BODY>
</HTML>
Thanks!