Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Fala galera e aew, beleza? entao to usando o codigo da nossa amiga Andreia de Combos de estados e cidades usando Ajax mas tva querendo implementar um novo filtro para uma 3 tabela.
a organizacao seria:
Paises / Cidades / Cursos.
Ja tenti de varias maneiras mas nao to conseguindo...sempre da algum erro.
Se tiverem como me ajudar...ficaria muito grato.
ajax_combo.asp
<!--#include file="conexao.asp"-->
<%
call abre_conexao
sql = "select id_estado, estado from estados order by estado"
set tab = conexao.execute(sql)
%>
<html>
<head>
<script src="seleciona_cidade.js"></script>
</head>
<title>Exemplo de Ajax</title>
<style type="text/css">
table
{
font-family: verdana;
font-size: 11px;
color: #000099;
font-weight: bold;
}
select
{
font-family: verdana;
font-size: 11px;
}
</style>
<body>
<table border="1" width="40%" cellspacing="0" cellpadding="5" bgcolor="#EAEBEF" bordercolorlight="#FFFFFF" bordercolordark="#E3E5EA">
<tr>
<td width="10%">Estado:</td>
<td width="30%"><select name="estados" onchange="MandaID(this.value)">
<option value="">Selecione</option>
<% while not tab.eof %>
<option value="<%= tab("id_estado") %>"><%= tab("estado") %></option>
<% tab.movenext
wend
%>
</select>
</td>
</tr>
<tr>
<td>Cidade:</td>
<td><div id="exibe_cidade"><select><option value="">Selecione um estado</option></select></div></td>
</tr>
</table>
<%
call fecha_conexao
set tab = nothing
%>
</body>
</html>
seleciona_cidade.js
var xmlHttp
function MandaID(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Este browser não suporta HTTP Request")
return
}
var url="seleciona_cidade.asp"
url=url+"?id_estado="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("exibe_cidade").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var objXMLHttp=null
if (window.XMLHttpRequest)
{
objXMLHttp=new XMLHttpRequest()
}
else if (window.ActiveXObject)
{
objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
}
return objXMLHttp
}
seleciona_cidade.asp
<!--#include file="conexao.asp"-->
<%
Response.Charset = "ISO-8859-1"
id_estado = request.querystring("id_estado")
%>
<select name="cidades">
<% if id_estado = "" then %>
<option value="">Selecione um estado</option>
<% else
call abre_conexao
sql_cidade="SELECT id_cidade, cidade FROM CIDADES WHERE id_estado="& id_estado
set tab_cidade = conexao.execute(sql_cidade)
while not tab_cidade.eof
%>
<option value="<%= tab_cidade("id_cidade") %>"><%= tab_cidade("cidade") %></option>
<% tab_cidade.movenext
wend
call fecha_conexao
set tab_cidade = nothing
end if
%>
</select>
Estrutura do Banco de Dados
>
Nome da tabela2: Cursos
Nome do campo1: id_curso (auto-numerico)
Nome do campo2: id_cidade (número)
Nome do campo3: curso (texto)
Nome da tabela1: Cidades
Nome do campo1: id_cidade (auto-numerico)
Nome do campo2: id_estado (número)
Nome do campo3: cidade (texto)
Nome da tabela2: Estados
Nome do campo1: id_estado (auto-numerico)
Nome do campo2: estado (texto)
Carregando comentários...