Hi,

I am using jQuery to fetch records from database.
On $(document).ready event i got all the categories including all the
subcategories using $.get() function.

But print only parent categories and put all the subcategories in div
tag which is hidden currently (style="display:none").

Now what i want to do is, on click of any parent category i want to
show div containing its subcategories.(<div
id="div_parentid">subcategories</div>).

code looks like this:

jQuery

$(document).ready(function(){

  $.get("leftMenu.php", function(data){

        $("#leftMenuHere").append(data);

  });

  $("#pcat").click(function(){
        alert($(this).value());
  });

});

Html:

<tr>
        <td id="leftMenuHere"></td>
</tr>


leftMenu.php

$categoryObj->getAllCategories();

#function used by category object.

#get all categories for left menu
        function getAllCategories($parent_id = "", $level=0){
                $space = "";
                if(!is_numeric($parent_id)){
                        $parent_id = 0;
                }
                for($j=0;$j<$level;$j++){
                        $space .= "&nbsp;&nbsp;&nbsp;";
                }
                $sql = "SELECT * FROM category WHERE parent_id = 
'".$parent_id."'";
                $sql .= "ORDER BY cat_name";
                $rslt = $this->dbclass->select($sql);
                if($rslt){
                        for($i=0;$i<count($rslt);$i++){
                                if($level > 0){
                                        echo "<div 
id='div_".$rslt[$i]["parent_id"]."'
style='display:none'>".$space.$rslt[$i]['cat_name']."</div>";
                                }
                                else{
                                        echo "<br><a 
href='index.php?file=category&icategory_id=".$rslt
[$i]['cat_id']."' class='menu2' id='pcat' value='".$rslt[$i]
["cat_id"]."'>".$space.$rslt[$i]["cat_name"]."</a>";
                                }
                                $this->getAllCategories($rslt[$i]["cat_id"], 
$level+1);
                        }
                }
        }


You can see demo what i want to do at :
http://www.futurebazaar.com/b2c_futurebazaar/catalog/categorieInPath.do?key=0/47E73548307C60F7E1000000A0330A05

copy and paste above link and see left menu.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to