Hi there,
I have these hirachical tree,I'm strugling to put checkbox on nodes only,for users to select a question they want to submit.
here is my code:
<style type="text/css">
.normal { background-color: white }
.normalActive { background-color: #DEE7EF;}
li{
list-style:none;
}
</style>
<script language="javascript">
function show(subCategory, path){
var thesub;
var theimage;
var imageid;
var testingdiv;
thesub = document.getElementById(subCategory);
imageid = "img_"+subCategory;
theimage = document.getElementById(imageid);
testingdiv = document.getElementById("testing");
if(thesub.style.display == 'block'){
//collapse...
thesub.style.display = 'none';
theimage.src = path+'images/c.gif';
/*
//testing...
testingdiv.style.display = 'block';
testingdiv.innerHTML = path+'common/parts_manuals/open.gif';
*/
}else{
//expand/display...
thesub.style.display = 'block';
theimage.src = path+'images/e.gif';
/*
//testing...
testingdiv.style.display = 'block';
testingdiv.innerHTML = path+'common/parts_manuals/up.gif';
*/
}
}
</script>
</head>
<body>
<div id="Layer3" style="position:absolute; left:5px; top:50px; width:750px; height:20px;">
<table width="100%">
<tr bgcolor="#AA0000"><td align="right"><font size="4" face="Arial, Helvetica, sans-serif" color="White"><strong>Nonconforming Event Report</strong></font></td></tr>
</table>
</div>
<div id="Layer5" style="position:absolute; left:5px; top:75px; width:750px; height:20px;">
<font size="2" face="Arial, Helvetica, sans-serif" color="Navy">
<?php
require_once("../shared/UserMenu.php"); //include User menus
$iIssueId = $_GET["iEventId"];
?>
</font>
</div>
<div id="Layer6" style="position:absolute; left:5px; top:100px; width:750px; height:40px;">
<font size="2" face="Arial, Helvetica, sans-serif" color="Navy">
<TABLE WIDTH="100%" CELLSPACING="0" BGCOLOR="#99CCFF">
<TR>
<TD VALIGN="BOTTOM">
</TD>
<TD ALIGN="RIGHT" VALIGN="BOTTOM">
<font size="-1" color="#000063">
<A HREF="NewEvent.php">New</A> |
<A HREF="EventSubmitted.php">All</A> |
<A HREF="EventAssigned.php"><strong>Mine</strong></A> |
<A HREF="EventResolved.php">Resolved</A> |
<A HREF="EventReport.php">Report</A>|
<A HREF="EventSearch.php">Search</A>
</font>
</TD>
</TR>
</TABLE>
</font>
</div>
<div id="Layer4" style="position:absolute; left:5px; top:105px; width:750px; height:520px; border: 1px none #000000"><br clear="all">
<font size="2" face="Arial, Helvetica, sans-serif" color="#000063">
<?php
$connection = mssql_connect($dbHost,$dbUser,$dbPass) or die("<p style='color:#FF0000;text-align:left;'>Cannot connect to database</p>");
$database = mssql_select_db($dbDbase) or die("<p style='color:#FF0000;text-align:left;'>Cannot select the database</p>");
//#########################################################################
$children = 0;
$no_children = array();
// $parent is the parent of the children we want to see
// $level is increased when we go deeper into the tree, used to display a nice indented tree
function display_children($parent, $level) {
global $children;
global $no_children;
// retrieve all children of $parent
/ $sql = sprintf("SELECT category_name, category_id, category_link
FROM categories
WHERE parent_id = %d",
$parent);
/
$sql = sprintf("SELECT category_no, category_desc, iParentId FROM n_CATEGORIES WHERE igroupid = 69 AND iuserid = 54 AND tiactive = 1 AND iParentId = %d ORDER BY iParentId",$parent);
$result = mssql_query($sql);
//if this is a sub category nest the list...
if($level > 0)
echo "<ul id='$parent' style='display:none;'>\n";
$list_id='';
// display each child
while ($row = mssql_fetch_array($result)) {
$children++;
$list_id = 'list_'.$children;
//display each child
echo '<li id="'.$list_id.'">';
echo '<a href="#" onClick="show('.$row['category_no'].', \''.$HTTP_PATH.'\')">';
echo '<img src="'.$HTTP_PATH.'images/c.gif" title="expand" border="0" id="img_'.$row['category_no'].'">';
echo '</a> ';
echo $row['category_desc']; " <span style='color:red;'>".$list_id."</span>";
echo '</li>';
// call this function again to display this child's children
display_children($row['category_no'], $level+1);
}
// $child_product = display_products($parent);
// if this is a sub category nest the list...
if($level > 0)
echo "</ul>\n";
$no_children[] = 'list_'.$children;
//if the category has at least one product in it allow us to expand and see that product...
if($child_product)
array_pop($no_children);
}
//#########################################################################
echo "<ul style='list-style:none;'>";
display_children('',0);
echo "</ul>";
/
echo "<pre style='color: red'> ";
print_r($no_children);
echo "</pre>";
/
?>
<!--<div style="display:block; border: 1px solid red;" id="testing"></div>-->
<script language="javascript" type="text/javascript">
function nokids(){
var kidnot;
kidnot = new Array();
<?php
for($i=0; $i<count($no_children); $i++){
print("kidnot.push(\"".$no_children[$i]."\");\n");
}
?>
for(i in kidnot){
var theid;
theid = kidnot[i];
//document.getElementById("testing").innerHTML += theid+", ";
document.getElementById(kidnot[i]).style.color = "green";
/*
var nodelings = document.getElementById(kidnot[i]).childNodes;
for(var i=0; i<nodelings.length; i++){
alert(nodelings[i]);
}
*/
}
}
</script>