nonprogrammer
Technical User
Hello All,
I bought a asp shopping cart that has a search and I have a script that has drop down boxes, I have been trying to combine both and I am having so many problems. could somebody give me a hand ?
here is the search
Here is the combo box script
I bought a asp shopping cart that has a search and I have a script that has drop down boxes, I have been trying to combine both and I am having so many problems. could somebody give me a hand ?
here is the search
Code:
<%
dim rs
ShopPageHeader
if Request("Action")<>"" then
GenerateSQLadvancedsearch
end if
ShopOpendatabase dbc
DisplaySearchForm
'response.write getsess("sql")
'set rs=dbc.execute(getsess("sql"))
'Do while not rs.eof
'response.write "catalogid" & rs("catalogid")
'rs.movenext
'Loop
'closerecordset rs
ShopClosedatabase dbc
ShopPageTrailer
Sub GenerateSQLadvancedsearch
dim sql,done
sql=""
dim strProductFields
dim i
dim strdistinct
dim whereok
strdistinct="DISTINCTROW"
if UCASE(xdatabasetype)="SQLSERVER" or ucase(getconfig("xdatabasetype"))="SQLSERVER" then
strdistinct="DISTINCT"
end if
strProductFields=Getsess("strProductFields")
If strProductFields="" then
GetProductfields dbc
strProductFields=Getsess("strProductFields")
end if
whereok=" and "
sql="select " & strdistinct & " " & strproductfields
sql=sql & " from products p, prodcategories cc, categories c"
sql=sql & " where cc.intcatalogid=p.catalogid and cc.intcategoryid=c.categoryid "
if request("categories") <> "" then
sql = sql & whereok & " cc.intcategoryid = " & request("categories")
end if
done=false
For each item in Request.Form
if lcase(Request.Form(item)) <>"" then
if item<>"Action" then
if item<>"categories" then
if item<>"Part_Number" then
sql = sql & whereok & item & "='" & Request.Form(item) & "'"
else
sql = sql & whereok & item & " like '%" & Request.Form(item) & "%'"
end if
done =true
end if
end if
end if
Next
setsess "SQL",sql
response.redirect "shopdisplayproducts.asp?Search=Yes"
response.write sql
End Sub
Sub GetProductFields (dbc)
dim sortfields, strproductfields
strproductfields="p.catalogid"
sortfields=lcase(getconfig("xsortproducts"))
sortfields=replace(sortfields," asc","")
sortfields=replace(sortfields," desc","")
sortfields=replace(lcase(sortfields),"catalogid","")
if sortfields<>"" Then
strproductfields=strproductfields & "," & sortfields
end if
setsess "strProductFields", strProductFields
end sub
Sub DisplaySearchForm
%>
<FORM method=post name=form1 action="advancedsearch.asp">
<TABLE cellpadding=0 cellspacing=0 border=0>
<TR height=50>
<TD align=center colspan=2>Part Number <%Dodropdown "Part_Number","Part_Number"%> </TD>
<TD align=center colspan=2>Category
<%Dodropdown "categories","categories"%> </TD>
</TR>
<TR height=20 bgcolor="#cccccc">
<TD align=center><B>Dimensions:</B></TD>
<TD align=center></TD>
<TD align=center></TD>
<TD align=center></TD>
</TR>
<TR height=50>
<TD align=center>Diameter: <%Dodropdown "PS_Diameter_A","Diameter_A"%> </TD>
<TD align=center>Height: <%Dodropdown "PS_Height_B","Height_B"%> </TD>
<TD align=center>Hub: <%Dodropdown "PS_Hub_C","Hub_C"%> </TD>
<TD align=center></TD>
</TR>
<TR height=50>
<TD align=center colspan=4><input type=submit name=Action value="Advanced Search"> </TD>
</TR>
</TABLE>
</FORM>
<%
End Sub
Sub Dodropdown (tablename,fieldname)
dim selected
dim sql
dim rs
dim description
dim i
if tablename="Part_Number" then
%>
<input type=text name=<%=fieldname%> size=20>
<%
else
sql="select * from " & tablename
set rs=dbc.execute(sql)
%>
<select name="<%=fieldname%>">
<option value="">Select a Value</option>
<%
Do while not rs.eof
if lcase(tablename)="categories" then
description=rs("catdescription")
id=rs("categoryid")
else
description=rs("description")
id=rs("id")
end if
if cstr(request(tablename))=cstr(id) then
selected=" SELECTED"
else
selected=""
end if
%>
<option value="<%=id%>" <%=selected%>><%=description%></option>
<%
rs.MoveNext
Loop
closerecordset rs
%>
</select>
<%
end if
End Sub
%>
Here is the combo box script
Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/dropdwn.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_dropdwn_STRING
Recordset1.Source = "SELECT * FROM Products"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()
Recordset1_numRows = 0
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<select name="Category" id="Category" onChange="TCN_reload(this)">
<option selected>Category</option>
</select>
<select name="SubCategory" id="SubCategory" onChange="TCN_reload(this)">
<option selected>SubCategory</option>
</select>
<select name="Diameter" id="Diameter" onChange="TCN_reload(this)">
<option selected>Diameter</option>
</select>
<select name="Height" id="Height" onChange="TCN_reload(this)">
<option selected>Height</option>
</select>
<select name="Hub" id="Hub" onChange="TCN_reload(this)">
<option selected>Hub</option>
</select>
<script language="JavaScript">
TCN_contents=new Array();
TCN_tempArray=new Array();
TCN_counter=0;
function TCN_addContent(str){
TCN_contents[TCN_counter]=str;
TCN_counter++;
}
function TCN_split(){
TCN_arrayValues = new Array();
for(i=0;i<TCN_contents.length;i++){
TCN_arrayValues[i]=TCN_contents[i].split(separator);
TCN_tempArray[0]=TCN_arrayValues;
}
}
function TCN_makeSelValueGroup(){
TCN_selValueGroup=new Array();
var args=TCN_makeSelValueGroup.arguments;
for(i=0;i<args.length;i++){
TCN_selValueGroup[i]=args[i];
TCN_tempArray[i]=new Array();
}
}
function TCN_makeComboGroup(){
TCN_comboGroup=new Array();
var args=TCN_makeComboGroup.arguments;
for(i=0;i<args.length;i++) TCN_comboGroup[i]=findObj(args[i]);
}
function TCN_setDefault(){
for (i=TCN_selValueGroup.length-1;i>=0;i--){
if(TCN_selValueGroup[i]!=""){
for(j=0;j<TCN_contents.length;j++){
if(TCN_arrayValues[j][(i*2)+1]==TCN_selValueGroup[i]){
for(k=i;k>=0;k--){
if(TCN_selValueGroup[k]=="") TCN_selValueGroup[k]=TCN_arrayValues[j][(k*2)+1];
}
}
}
}
}
}
function TCN_loadMenu(daIndex){
var selectionMade=false;
daArray=TCN_tempArray[daIndex];
TCN_comboGroup[daIndex].options.length=0;
for(i=0;i<daArray.length;i++){
existe=false;
for(j=0;j<TCN_comboGroup[daIndex].options.length;j++){
if(daArray[i][(daIndex*2)+1]==TCN_comboGroup[daIndex].options[j].value) existe=true;
}
if(existe==false){
lastValue=TCN_comboGroup[daIndex].options.length;
TCN_comboGroup[daIndex].options[TCN_comboGroup[daIndex].options.length]=new Option(daArray[i][daIndex*2],daArray[i][(daIndex*2)+1]);
if(TCN_selValueGroup[daIndex]==TCN_comboGroup[daIndex].options[lastValue].value){
TCN_comboGroup[daIndex].options[lastValue].selected=true;
selectionMade=true;
}
}
}
if(selectionMade==false) TCN_comboGroup[daIndex].options[0].selected=true;
}
function TCN_reload(from){
if(!from){
TCN_split();
TCN_setDefault();
TCN_loadMenu(0);
TCN_reload(TCN_comboGroup[0]);
}else{
for(j=0; j<TCN_comboGroup.length; j++){
if(TCN_comboGroup[j]==from) index=j+1;
}
if(index<TCN_comboGroup.length){
TCN_tempArray[index].length=0;
for(i=0;i<TCN_comboGroup[index-1].options.length;i++){
if(TCN_comboGroup[index-1].options[i].selected==true){
for(j=0;j<TCN_tempArray[index-1].length;j++){
if(TCN_comboGroup[index-1].options[i].value==TCN_tempArray[index-1][j][(index*2)-1]) TCN_tempArray[index][TCN_tempArray[index].length]=TCN_tempArray[index-1][j];
}
}
}
TCN_loadMenu(index);
TCN_reload(TCN_comboGroup[index]);
}
}
}
function findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
TCN_makeSelValueGroup("","","","","");
TCN_makeComboGroup("Category","SubCategory","Diameter","Height","Hub");
var separator="+#+";
<% Do While NOT Recordset1.EOF %>TCN_addContent("<%=(Recordset1.Fields.Item("ccode").Value)%>+#+<%=(Recordset1.Fields.Item("ccode").Value)%>+#+<%=(Recordset1.Fields.Item("ccode").Value)%>+#+<%=(Recordset1.Fields.Item("scode").Value)%>+#+<%=(Recordset1.Fields.Item("Diameter_Aname").Value)%>+#+<%=(Recordset1.Fields.Item("Diameter_A").Value)%>+#+<%=(Recordset1.Fields.Item("Height_Bname").Value)%>+#+<%=(Recordset1.Fields.Item("Height_B").Value)%>+#+<%=(Recordset1.Fields.Item("Hub_Cname").Value)%>+#+<%=(Recordset1.Fields.Item("Hub_C").Value)%>");
<% Recordset1.MoveNext
Loop
%>
TCN_reload();
TCN_setDefault();
</script>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>