Need to switch tabs with select
. What's the best practice? My idea is to manipulate class .active
with onChange
event. But I believe there must be something better.
Here's some code sample:
<select id="mySelect">
<option value="tab1">Tab 1</option>
<option value="tab2">Tab 2</option>
<option value="tab3">Tab 3</option>
</select>
<div id="myTabContent" class="tab-content">
<div class="tab-pane fade in active" id="tab1">
<div id="calendari_3">asd</div>
</div>
<div class="tab-pane fade" id="tab2">
<div id="calendari_1">qwe</div>
</div>
<div class="tab-pane fade" id="tab3">
<div id="calendari_2">asw</div>
</div>
</div>
I guess you can call the 'show' method yourself, on any event.
http://jsfiddle.net/7Wv5h/40/ [updated]
JS:
// jQuery and Bootstrap loaded, you're here on a $(document).on('ready') scope !
$('#your-select').on('change', function (e) {
// With $(this).val(), you can **(and have to!)** specify the target in your <option> values.
$('#the-tab li a').eq($(this).val()).tab('show');
// If you do not care about the sorting, you can work with $(this).index().
// $('#the-tab li a').eq($(this).index()).tab('show');
});
HTML:
<form>
<select id='mySelect'>
<option value='0'>Home</option>
<option value='1'>Profile</option>
<option value='2'>Messages</option>
<option value='3'>Settings</option>
</select>
</form>
<ul class="nav nav-tabs" id="myTab">
<li class="active"><a href="#home">Home</a></li>
<li><a href="#profile">Profile</a></li>
<li><a href="#messages">Messages</a></li>
<li><a href="#settings">Settings</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="home">Home content</div>
<div class="tab-pane" id="profile">Profile content</div>
<div class="tab-pane" id="messages">Messages content</div>
<div class="tab-pane" id="settings">Settings content</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With