Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
'assume our recordset is called rsCats
Dim last_name
'very important to MoveFirst befoe we do anything, re-ordering sometimes sends back a recordset with the pointer pointing somewhere in the midle instead of the top
If Not rsCats.EOF The rsCats.MoveFirst
Do Until rsCats.EOF
'is this a new groups of make/models?
If last_name <> lcase(rsCats("make_name")) Then
'output the make name
Response.Write "<b>" & rsCats("make_name") & "</b><br>"
'set the last name
last_name = lcase(rsCats("make_name"))
End If
'output the model name every time
Response.Write rsCats("model") & "<br>"
'next record
rsCats.MoveNext
Loop
<html>
<head>
<style>
span, div{ margin: 2px; }
.node{ border: 1px solid blue; }
.node_children{ border: 1px solid green; margin-left: 25px}
.node_toggle{ border: 1px solid #999999; width: 20px; text-align: Center;}
.node_name{ border: 1px solid #FF0099; }
</style>
</head>
<body>
<div class="node"><span class="node_toggle">+</span><span class="node_name">Parent Node</span>
<div class="node_children">
child<br>
child<br>
child
</div>
</div>
Node: Blue<br>
Node CHildren: Green<br>
Node Toggle: Grey<br>
Node Name: Purple/Pink<br>
</body>
</html>
Dim last_name
If Not rsCats.EOF The rsCats.MoveFirst
Do Until rsCats.EOF
'is this a new groups of make/models?
If last_name <> lcase(rsCats("make_name")) Then
'--- We need to start a node div and end the previous one if there was one
'check for previous open category
If len(last_name) > 0 Then
'end the node_children and the node divs
Response.Write "</div></div>"
End If
'--- Output a node div to enclose everything
Response.Write "<div class=""node"">"
'output a toggle span to precede the name
Response.Write "<span class=""node_toggle"">+</span>"
'output the make name --- with span tags
Response.Write "<span class=""node_name"">" & rsCats("make_name") & "</span>"
'--- Now we need to start the children's node
Response.Write "<div class=""node_children"">"
'set the last name
last_name = lcase(rsCats("make_name"))
End If
'output the model name every time
Response.Write rsCats("model") & "<br>"
'next record
rsCats.MoveNext
Loop
'--- We need to end any outstanding nodes and node_children
If len(last_name) > 0 Then
Response.Write "</div></div>"
End If
<%
'Somewhere up here we're making our recordset
%>
<html>
<head>
<style>
.node{
margin-left: 25px
padding-left: 5px;
}
.node_children{
/* by default we will hide the children */
display: none;
}
.node_toggle{
/* we need a fixed width because +/- aren't same width
and will make stuff bounce around when we change them.
We also want to add a hand cursor when they mouse over
a toggle to make it more obvious they can click it */
width: 20px;
text-align: center;
cursor: hand;
}
</style>
</head>
<body>
<%
Dim last_name
If Not rsCats.EOF The rsCats.MoveFirst
Do Until rsCats.EOF
'is this a new groups of make/models?
If last_name <> lcase(rsCats("make_name")) Then
'We need to start a node div and end the previous one if there was one
'check for previous open category
If len(last_name) > 0 Then
'end the node_children and the node divs
Response.Write "</div></div>"
End If
'output a node div to enclose everything
Response.Write "<div class=""node"">"
'output a toggle div to precede the name
Response.Write "<div class=""node_toggle"">+</div>"
'output the make name
Response.Write rsCats("make_name")
'we need to start the children's node
Response.Write "<div class=""node_children"">"
'set the last name
last_name = lcase(rsCats("make_name"))
End If
'output the model name every time
Response.Write rsCats("model") & "<br>"
'next record
rsCats.MoveNext
Loop
'end any outstanding nodes and node_children
If len(last_name) > 0 Then
Response.Write "</div></div>"
End If
%>
</body>
</html>
<script language="javascript">//first redirect all click events to the navClicked function
document.onclick = navClicked;
function switchPoint(aNavPoint){
var collapsed;
if(aNavPoint.innerHTML == "+"){
collapsed=false;
aNavPoint.innerHTML = "-";
}
else{
collapsed=true;
aNavPoint.innerHTML = "+";
}
return collapsed;
}
function navClicked(e){
//assume the click was on a switchPoint and that it is collapsed
var isCollapsed = true;
//get a reference to the element that was clicked
// non-IE browsers get passed the event, IE needs to grab it from window
if(!e){
var elem = window.event.srcElement;
}
else{
var elem = e.target;
}
var nodelist = elem.parentNode.childNodes[2];
//if the element that was clicked on was one of the toggles
if(elem.className == "node_toggle"){
//call the switchpoint function to change it's state, ie "+" to "-" and "-" to "+"
isCollapsed = switchPoint(elem);
//if the item is now collapsed after switching
if(isCollapsed)
//get it's parent element, get the parents third child (element_contents), hide it
nodelist.style.display = "none";
else
//otherwise open it's element_contents sibling
nodelist.style.display = "inline";
}
}
</script>
<style>
.node{
margin-left:25px;
padding-left: 5px;
}
.node_children{
display:none;
}
.node_toggle{
width:20px;
text-decoration:none;
text-align:center;
color:#666666;
cursor:hand;
}
.node_no_toggle{
width:20px;
text-decoration:none;
}
</style>
<div class="tree_view">
<div class="node"><span class="node_toggle">+</span><span class="node_text">Parent 1</span>
<div class="node_children" style="display:none;">
<div class="node"><span class="node_no_toggle"> </span><span class="node_text">Child 1 (Parent 1)</span></div>
<div class="node"><span class="node_no_toggle"> </span><span class="node_text">Child 2 (Parent 1)</span></div>
<div class="node"><span class="node_no_toggle"> </span><span class="node_text">Child 3 (Parent 1)</span></div>
</div>
</div>
<div class="node"><span class="node_toggle">+</span><span class="node_text">Parent 2</span>
<div class="node_children" style="display:none;">
<div class="node"><span class="node_no_toggle"> </span><span class="node_text">Child 1 (Parent 2)</span></div>
<div class="node"><span class="node_toggle">+</span><span class="node_text">Child 2 (Parent 2)</span>
<div class="node_children" style="display:none;">
<div class="node"><span class="node_no_toggle"> </span><span class="node_text">Child 1 (Parent 2-2)</span></div>
<div class="node"><span class="node_no_toggle"> </span><span class="node_text">Child 2 (Parent 2-2)</span></div>
<div class="node"><span class="node_no_toggle"> </span><span class="node_text">Child 3 (Parent 2-2)</span></div>
</div>
</div>
<div class="node"><span class="node_no_toggle"> </span><span class="node_text">Child 3 (Parent 2)</span></div>
</div>
</div>
<div class="node"><span class="node_no_toggle"> </span><span class="node_text">Parent 3</span></div>
<div class="node"><span class="node_toggle">+</span><span class="node_text">Parent 4</span>
<div class="node_children" style="display:none;">
<div class="node"><span class="node_no_toggle"> </span><span class="node_text">Child 1 (Parent 4)</span></div>
<div class="node"><span class="node_no_toggle"> </span><span class="node_text">Child 2 (Parent 4)</span></div>
<div class="node"><span class="node_no_toggle"> </span><span class="node_text">Child 3 (Parent 4)</span></div>
</div>
</div>
</div>