R
rjpeek36
I have a tree menu that is created using PHP. PHP loads each node from
a MySQL database and then PHP displays it to the user. I use
Javascript to toggle the displayed node icons from open to closed and
then back when the user clicks the node icon. When the menu first
loads all the nodes are opened and the vertical scroll bar is at the
top. When the user scrolls down to view a node at the bottom of the
page and then clicks on a node located toward the bottom, the node
icon and content close/hide and the scrollbar moves to the top. How do
I retain the scroll position after a user clicks on node icon?
function Toggle(item)
{
obj=document.getElementById(item);
visible=(obj.style.display!="none")
key=document.getElementById("x" + item);
if (visible)
{
obj.style.display="none";
key.innerHTML= "<img src='folder.gif' hspace='0' vspace='0'
border='0'>";
}
else
{
obj.style.display="block";
key.innerHTML= "<img src='textfolder.gif' hspace='0' vspace='0'
border='0'>";
}
}
$sqlConn = mysql_connect($server, $user, $password) or die("Couldn't
connect to database");
$dbConn = mysql_select_db($database, $sqlConn) or die("Couldn't
connect to database");
$sql = "select * from menu where parentid = 0 order by title asc";
$nodeResult = mysql_query($sql) or die("SELECT query failed");
$counter = 0;
$level=0;
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
Scroll Bar, Example 2
<table cellpadding='10' cellspacing='0'>
<tr><td>
<?php
while($node = mysql_fetch_assoc($nodeResult))
{
$selected_link=$node["title"];
?>
<table id=main_table cellpadding="1" cellspacing="1">
<tr>
<td>
<?php
echo "<a id=x$counter href='#' onClick=javascript:Toggle($counter)>";
?>
<?php
if ($selected_links[$level]==$node["title"])
{
$display="block";
echo "<img src='/images/textfolder.gif' width='16' height='16'
hspace='0' vspace='0' border='0'>";
}
else
{
$display="none";
echo "<img src='/images/folder.gif' width='16' height='16'
hspace='0' vspace='0' border='0'>";
}
?>
</a>
</td>
<td id="title<?php echo $counter; ?>"><b>
<?php
echo "<a id=x$counter href='#' onClick=javascript:Toggle($counter)>";
echo $node["title"];
echo "</a>";
?>
</b>
</td>
</tr>
</table>
<div id="<?php echo $counter; ?>" style="display:block; margin-left:
2em;">
<?php
$counter=@sublevel($node["id"], $counter, $level, $content_page,
$sub_content_page, $state_data, $selected_link, $selected_links);
?>
</div>
<?php $counter++; ?>
<?php
}
?>
</td></tr>
</table>
</body>
a MySQL database and then PHP displays it to the user. I use
Javascript to toggle the displayed node icons from open to closed and
then back when the user clicks the node icon. When the menu first
loads all the nodes are opened and the vertical scroll bar is at the
top. When the user scrolls down to view a node at the bottom of the
page and then clicks on a node located toward the bottom, the node
icon and content close/hide and the scrollbar moves to the top. How do
I retain the scroll position after a user clicks on node icon?
function Toggle(item)
{
obj=document.getElementById(item);
visible=(obj.style.display!="none")
key=document.getElementById("x" + item);
if (visible)
{
obj.style.display="none";
key.innerHTML= "<img src='folder.gif' hspace='0' vspace='0'
border='0'>";
}
else
{
obj.style.display="block";
key.innerHTML= "<img src='textfolder.gif' hspace='0' vspace='0'
border='0'>";
}
}
$sqlConn = mysql_connect($server, $user, $password) or die("Couldn't
connect to database");
$dbConn = mysql_select_db($database, $sqlConn) or die("Couldn't
connect to database");
$sql = "select * from menu where parentid = 0 order by title asc";
$nodeResult = mysql_query($sql) or die("SELECT query failed");
$counter = 0;
$level=0;
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
Scroll Bar, Example 2
<table cellpadding='10' cellspacing='0'>
<tr><td>
<?php
while($node = mysql_fetch_assoc($nodeResult))
{
$selected_link=$node["title"];
?>
<table id=main_table cellpadding="1" cellspacing="1">
<tr>
<td>
<?php
echo "<a id=x$counter href='#' onClick=javascript:Toggle($counter)>";
?>
<?php
if ($selected_links[$level]==$node["title"])
{
$display="block";
echo "<img src='/images/textfolder.gif' width='16' height='16'
hspace='0' vspace='0' border='0'>";
}
else
{
$display="none";
echo "<img src='/images/folder.gif' width='16' height='16'
hspace='0' vspace='0' border='0'>";
}
?>
</a>
</td>
<td id="title<?php echo $counter; ?>"><b>
<?php
echo "<a id=x$counter href='#' onClick=javascript:Toggle($counter)>";
echo $node["title"];
echo "</a>";
?>
</b>
</td>
</tr>
</table>
<div id="<?php echo $counter; ?>" style="display:block; margin-left:
2em;">
<?php
$counter=@sublevel($node["id"], $counter, $level, $content_page,
$sub_content_page, $state_data, $selected_link, $selected_links);
?>
</div>
<?php $counter++; ?>
<?php
}
?>
</td></tr>
</table>
</body>