Thursday, March 24, 2011

Make Tab Dynamically Active Using JQuery and PHP

   // Some condition According to this assign valoues of $tab_act as 0, 1, 2
  // First Condition
  if(!empty($_GET)){
    $tab_act = 1;
  }else{
     $tab_act = 0;
  }
// Second Condition if Values are come through url make it an array
$name = explode('/',$_SERVER['REQUEST_URI']);
$name_url = $name['1'];
if($name_url == ''){
   $tab_act = 0;
} else{
   $tab_act = 1;
}
// Note :- Use Condition According to your requirement and assign values in $tab_act = 0;
?>

$(document).ready(function() {

//When page loads...
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:eq()").addClass("active").show(); //Activate first tab
$(".tab_content:eq()").show(); //Show first tab content

//On Click Event
$("ul.tabs li").click(function() {

$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content

var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
});

1 comment: