I have two tables in SQL: A group that has two columns: id and group
A product that has three columns: id, group, and product
In the Products table, the "group" column is equivalent to the "id" column of the groups table.
I'm trying to make an inclusion form into a third table of entries (columns: group, product, and entry).
In this form, there is a combobox in which the user will select the Group and, when selecting the Group, should appear in a second combobox only the Products related to it. (similar to the state / city combobox).
The webpage is connecting right into the database, but I am not able to make the combobox dependent.
I built it as follows:
Combo of two groups:
<%
SET RS_grupo = conexao.execute("SELECT * FROM [dbo].[nova_pd_grupos] ORDER BY grupo")
grupo1= RS_grupo("grupo")
idgrupo=RS_grupo("id")
grupo=request.querystring("grupo1")
%>
<select class="custom-select custom-select-sm" name="idgrupo" onChange="location.href('index.asp?idgrupo='+formulario.idgrupo.options[formulario.idgrupo.selectedIndex].value)">
<% while not RS_grupo.eof%>
<% if grupo <>"" then
if grupo = grupo1 then
response.write "<option value="&idgrupo&"&grupo1="&grupo1&" selected>"&grupo1&"</option>"
elseif grupo <> grupo1 then
response.write "<option value="&idgrupo&"&grupo1="&grupo1&">"&grupo1&"</option>"
end if
else
response.write "<option value="&idgrupo&"&grupo1="&grupo1&">"&grupo1&"</option>"
end if
RS_grupo.movenext
wend
RS_grupo.close
%>
</select>
Combo of products:
<% if request.querystring("idgrupo") <> "" then %>
<select class="custom-select custom-select-sm" name="produto">
<% SET RS_produto = conexao.execute("SELECT * FROM [dbo].[nova_pd_produtos] where grupo = "&request.querystring("idgrupo")&" order by produto asc;")
while not RS_produto.eof
grupo = request.querystring("grupo")
produto1 = RS_produto("produto")
%>
<option value="<%=produto1%>,<%=grupo%>">
<%=produto1%>
</option>
<%
RS_produto.movenext
wend
RS_produto.close
%>
</select>
<% end if %>
However, 13 options appear in the group list, all with the name of the first option. And in the list of products nothing appears.
Can anyone help me? Classic ASP (vbscript).
Thank you!