Basit bir kategori seçici yazdım şimdi. Mantığını çözdükten sonra, kolayca sitenize uyarlayabilirsiniz.
kategori_sec.asp
<%
Response.ContentType = "text/html"
Response.Charset = "utf-8"
Set Baglan = Server.CreateObject("Adodb.Connection")
Baglan.Open "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & Server.MapPath("/r10-yardim/vt.mdb")
Set KS1 = Baglan.Execute("Select * From ana_kategori")
Set KS2 = Baglan.Execute("Select * From alt_kategori Where ana_kat_id=1")
Set KS3 = Baglan.Execute("Select * From son_kategori Where ana_kat_id=1")
%>
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="utf-8" />
<script>
function showHint(str, islem)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if(islem==1){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("alt_kategori").innerHTML=xmlhttp.responseText;
}
}
if(islem==2){
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("son_kategori").innerHTML=xmlhttp.responseText;
}
}
}
xmlhttp.open("GET","Ajax.asp?"+str,true);
xmlhttp.send();
}
</script>
</head
><body>
<p><b>Lütfen ürün kategorilerini seçin</b></p>
<form>
<select onChange="showHint(this.value, 1)">
<%Do Until KS1.EOF%>
<option value="ana_kat=<%=KS1("id")%>"><%=KS1("kategori_adi")%></option>
<%KS1.MoveNext : Loop%>
</select>
<select id="alt_kategori" onChange="showHint(this.value, 2)">
<%Do Until KS2.EOF%>
<option value="alt_kat=<%=KS2("id")%>"><%=KS2("kategori_adi")%></option>
<%KS2.MoveNext : Loop%>
</select>
<select id="son_kategori">
<%Do Until KS3.EOF%>
<option value="son_kat=<%=KS3("id")%>"><%=KS3("kategori_adi")%></option>
<%KS3.MoveNext : Loop%>
</select>
</form>
</body>
</html>Ajax.asp
<%
Response.ContentType = "text/html"
Response.Charset = "utf-8"
Set Baglan = Server.CreateObject("Adodb.Connection")
Baglan.Open "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & Server.MapPath("/r10-yardim/vt.mdb")
If Request.QueryString("ana_kat") <> "" Then
Set KS2 = Baglan.Execute("Select * From alt_kategori Where ana_kat_id=" & Request.QueryString("ana_kat"))
Do Until KS2.EOF
Response.Write("<option value=""alt_kat=" & KS2("id") & """>" & KS2("kategori_adi") & "</option>" & VbCrlf)
KS2.MoveNext : Loop
ElseIf Request.QueryString("alt_kat") <> "" Then
Set KS3 = Baglan.Execute("Select * From son_kategori Where alt_kat_id=" & Request.QueryString("alt_kat"))
Do Until KS3.EOF
Response.Write("<option value=""alt_kat=" & KS3("id") & """>" & KS3("kategori_adi") & "</option>" & VbCrlf)
KS3.MoveNext : Loop
End If
%>Dosyaları indirmek için:
Kategori-Secimi(AJAX-ASP).zip
Her iki sayfada da veritabanı yolunu değiştirmeyi unutmayın.