I am still not able to get this working in a simple page. Please help me. I am badly stuck....
I am trying to view the contents of the Beverage Category. I have built it like a hierarchy in the form of styled <UL> tags.
Please assist me in combining the 2 pages into one page. I would extremely grateful.
My code is:
Categories_Dynamic.asp
Expand|Select|Wrap|Line Numbers
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <!--#INCLUDE Virtual="/Scripts/Padmaja/Testing2/DB_Northwind.asp"-->
- <head>
- <style type="text/css">
- * {
- border: 0;
- padding: 0;
- margin: 0;
- }
- #menu {
- padding:0;
- margin:0;
- }
- #menu li {
- list-style-type:none;
- }
- #menu ul {
- padding: 0;
- margin: 6px;
- list-style-type: none;
- }
- a.a_style:link {color:#0000ff; text-decoration:none;}
- a.a_style:visited {color:#0000ff; text-decoration:none;}
- a.a_style:hover {color:#ff0000; text-decoration:underline;}
- a.a_style:hover {color:#ff0000; text-decoration:underline;}
- </style>
- <script type="text/javascript">
- var xmlHttp
- function showProducts(str)
- {
- xmlHttp=GetXmlHttpObject()
- if (xmlHttp==null)
- {
- alert ("Browser does not support HTTP Request")
- return
- }
- var url="getProducts.asp"
- url=url+"?ID="+str
- //alert(url);
- //url=url+"&sid="+Math.random()
- xmlHttp.onreadystatechange=stateChanged1
- xmlHttp.open("GET",url,true)
- xmlHttp.send(null)
- }
- function stateChanged1()
- {
- if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
- {
- //objID = 'UI_'+el;
- //document.getElementById(objID).innerHTML=xmlHttp.responseText
- document.getElementById("content_products").innerHTML=xmlHttp.responseText
- }
- }
- function GetXmlHttpObject()
- {
- var objXMLHttp=null
- if (window.XMLHttpRequest) //Safari, Mozilla browers
- {
- objXMLHttp=new XMLHttpRequest()
- }
- else if (window.ActiveXObject) //IE browsers
- {
- objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
- }
- return objXMLHttp
- }
- function s_Hide(el){
- //alert("Showing Element: "+el);
- objID = 'UI_'+el;
- //alert(objID);
- obj = document.getElementById(objID).style;
- (obj.display == 'none')? obj.display = 'block' : obj.display = 'none';
- }
- </script>
- <title>On Demand Building of tree with User OnClick</title>
- </head>
- <body>
- <form name="Customers" id="Customers" action="">
- <%
- Dim rs
- Set rs = Server.CreateObject("ADODB.Recordset")
- sSQL = "SELECT CategoryID, CategoryName FROM Categories WHERE CategoryID = 2"
- rs.open sSQL, Conn
- Dim aCategory
- If not rs.EOF Then
- 'Dump the recordset into the above array
- aCategory = rs.getRows()
- rs.Close
- Set rs = Nothing
- Dim iRows
- For iRows = 0 to UBound(aCategory, 2)
- CatID = aCategory(0, iRows)
- %>
- <ul id="menu">
- <li>
- <input type="radio" checked name="prodid" id="Catid<%=aCategory(0, iRows)%>" value="<%=aCategory(0, iRows)%>">
- <a href="#" class="a_style" onclick="showProducts(<%=aCategory(0, iRows)%>);s_Hide('<%=aCategory(0, iRows)%>'); return false;"><%=aCategory(1, iRows)%></a>
- <ul id="UI_<%=aCategory(0, iRows)%>">
- <%
- 'QS = Request.Querystring("ID")
- 'Now pass the querystring to the following function.
- 'if QS = trim(aCategory(0, iRows)) then
- 'Call GetProducts (CatID, Counter)
- 'end if
- %>
- <div id="content_products">
- </div>
- </ul>
- </li>
- </ul>
- <%
- Next 'iRows
- End If
- %>
- </form>
- </body>
- </html>
- <%
- Conn.Close
- Set Conn = Nothing
- %>
Expand|Select|Wrap|Line Numbers
- <%
- ProdID = Request.Querystring("ID")
- 'Response.Write ProdID
- Call GetProducts (ProdID, Counter)
- startTime = Now()
- 'get the Products using a function
- Function GetProducts(ProdID, Counter)
- sql = "SELECT CategoryID, ProductName, ProductID FROM Products " & _
- "where CategoryID = " & ProdID & " " & _
- "order by ProductName "
- 'Response.Write sql
- 'Response.End
- Dim rs2
- set rs2 = Server.CreateObject("ADODB.Recordset")
- rs2.open sql, Conn
- Dim aProducts
- If not rs2.EOF then
- aProducts = rs2.GetRows()
- 'Close Recordset to use the new array with the 2 columns data
- rs2.Close()
- set rs2 = Nothing
- 'Declare Constants for the above SQL columns for better readability
- 'Use these Constants instead of referring to the array numeric indexes
- Const c_CatID = 0
- Const c_ProductName = 1
- Const c_ProductID = 2
- 'Ubound(MyArray,1) 'Returns the Number of Columns
- 'Ubound(MyArray,2) 'Returns the Number of Rows
- Dim iRowLoop
- For iRowLoop = 0 to UBound(aProducts, 2)
- %>
- <li>
- <input type="radio" name="prodid" id="prodid<%=aProducts(c_ProductID,iRowLoop)%>" value="<%=aProducts(c_ProductID,iRowLoop)%>">
- <%=aProducts(c_ProductName,iRowLoop)%>
- <%
- Counter = Counter + 1
- Counter = Counter - 1
- %>
- </li>
- <%
- Next 'iRowLoop
- End If 'rs2.EOF
- End Function
- %>