php - Search for tab and replace it with active one -
problem:
to search tab containing class "active" , remove while adding "active" class current tab on php post submission.
i have tab menu looks this.
html code:
<div class="pull-right special-search" id="navtabs"> <div class="btn-group"> <a href="#tab1" class="active btn btn-info" data-toggle="tab"><i class="icon-home icon-white"></i> start</a> <a href="#tab2" class="btn btn-info" data-toggle="tab"><i class="icon-book icon-white"></i> essay</a> <a href="#tab3" class="btn btn-info" data-toggle="tab"><i class="icon-ok-sign icon-white"></i> criteria</a> <a href="#tab4" class="btn btn-info" data-toggle="tab"><i class="icon-time icon-white"></i> activity</a> </div> </div> to toggle between these tabs use following jquery code:
$('#navtabs a[data-toggle="tab"]').on('shown', function (e) { e.target; e.relatedtarget; $('#navtabs a[data-toggle="tab"]').attr('class','btn btn-info'); $(this).attr('class','active btn btn-info'); }) so far, good. works. now, when press button "submit-updatetime" want checked php correspondent tab sent from. using hidden type field:
<input type="hidden" id="submit_button" name="button_pressed"> and check php using following code:
<?php if ($_server['request_method'] == 'post') { $button = $_post['button_pressed']; if ($button == 'submit-updategrades') $tabname = 'tab2'; else if ($button == 'submit-updatetime') $tabname = 'tab4'; } ?> to make sure user stays on tab he/she on use following php/jquery:
<?php if (!empty($tabname)) { echo '$("#navtabs a[href=#tab1]").removeclass(\'active\');'; echo '$("#tab1").removeclass(\'active\');'; echo '$("#navtabs a[href=#'.$tabname.']").addclass(\'active\');'; echo '$("#'.$tabname.'").addclass(\'active\');'; } ?> this works fine except feel last php/jquery solution flawed. instance, #tab1 active when enter page, not time.
question:
how in last php/jquery code search tab has class "active" , remove while @ same time add active tab produced $tabname?
ho wo find tab has active class:
$(document).ready(function(){ var tab = $('#navtabs a.active'); }); remove active class on tab found:
$(document).ready(function(){ var tab = $('#navtabs a.active'); tab.removeclass('active'); }); find, remove , add active class tab provided php:
<?php if (!empty($tabname)) { ?> $(document).ready(function(){ var active_tab = '#<?php echo $tabname; ?>'; var tab = $('#navtabs a.active'); tab.removeclass('active'); $('#navtabs a').each(function(){ if($(this).attr('href') == active_tab) { $(this).addclass('active'); return; } }); }); <?php } ?>
Comments
Post a Comment