ReportingAnalyst
MIS
Hi,
I am building a sample ASP page which pulls from the Northwind database where I display the category Beverage and on click of the "Beverage" link, I can pass the category id to the sql statement to display the products which fall under the "Beverage" category. Now I want to include AJAX to this so that I do not see the page re-load.
At the same time, when I click on the Beverage link, if it is expanded, then it should collapse, and it is collapsed, then it should expand.
Can I do this?
ASP part:
My Javascript part is:
I am building a sample ASP page which pulls from the Northwind database where I display the category Beverage and on click of the "Beverage" link, I can pass the category id to the sql statement to display the products which fall under the "Beverage" category. Now I want to include AJAX to this so that I do not see the page re-load.
At the same time, when I click on the Beverage link, if it is expanded, then it should collapse, and it is collapsed, then it should expand.
Can I do this?
ASP part:
Code:
<ul id="menu">
<li>
<input type="radio" checked name="prodid" id="Catid<%=aCategory(0, iRows)%>" value="<%=aCategory(0, iRows)%>">
<a href="Categories_dynamic.asp?ID=<%=aCategory(0, iRows)%>" class="a_style" onclick="showProducts(<%=aCategory(0, iRows)%>)"><%=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 (QS, Counter)
end if
%>
</ul>
</li>
</ul>
My Javascript part is:
Code:
function showProducts(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="Categories_dynamic.asp"
url=url+"?q="+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")
{
//get the element ID of this UL tag which I would like to show for the above category. I would not like to use div tags because I have styled UL tags. How can I get the UL tag ID into this line
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
}
//How to include this function in the above Javascript function
/*function s_Hide(el){
objID = 'UI_'+el;
obj = document.getElementById(objID).style;
(obj.display == 'none')? obj.display = 'block' : obj.display = 'none';
}*/