Reputation: 693
I use bootstrap tabs, and I would like to open specific tab from my CI controller. Code in my view look like this:
<ul class="nav nav-tabs" id="myTabs">
<li class="active"><a href="#tabs1-pane1" data-toggle="tab">Tab 1</a></li>
<li><a href="#tabs1-pane2" data-toggle="tab">Tab 2</a></li>
<li><a href="#tabs1-pane3" data-toggle="tab">Tab 3</a></li>
<li><a href="#tabs1-pane4" data-toggle="tab">Tab 4</a></li>
</ul>
Now, i would like to process some data in my controller and when done, I want to open the Tab 3
I am trying with something like this:
redirect(base_url()."hoteldetails/showHotel/".$hotelID."/#tabs1-pane3");
but the first tab is opened, instead of third tab.
Anyone can suggest some solution?
Regards, John
Upvotes: 2
Views: 3634
Reputation: 1823
You could do it this way;
<?php $tab = (isset($_GET['tab'])) ? $_GET['tab'] : null; ?>
<ul class="nav nav-tabs" id="myTabs">
<li class="<?php echo ($tab == 'tab1') ? 'active' : ''; ?>"><a href="<?php echo site_url('hoteldetails/showHotel/13?tab=tab1'); ?>">Tab 1</a></li>
<li class="<?php echo ($tab == 'tab2') ? 'active' : ''; ?>"><a href="<?php echo site_url('hoteldetails/showHotel/13?tab=tab2'); ?>">Tab 2</a></li>
<li class="<?php echo ($tab == 'tab3') ? 'active' : ''; ?>"><a href="<?php echo site_url('hoteldetails/showHotel/13?tab=tab3'); ?>">Tab 3</a></li>
<li class="<?php echo ($tab == 'tab4') ? 'active' : ''; ?>"><a href="<?php echo site_url('hoteldetails/showHotel/13?tab=tab4'); ?>">Tab 4</a></li>
</ul>
Then, you should change each tab-pane, to have the active class too;
<div class="tab-pane <?php echo ($tab == 'tab1') ? 'active' : ''; ?>" id="tabs1-pane1">
Upvotes: 2