Solved

get id of current tab, beforeActivate

Posted on 2013-05-12
8
3,992 Views
Last Modified: 2013-05-13
I found code to provide enable canceling of switching tabs, but I need to run code specific to the ID of the currently selected tab.  How do I get the currently selected tab, not the tab clicked on?  I tried the beforeActivate  ui.oldTab but that returned "undefined".


$("#myTabs").tabs({ 
    beforeActivate: function(event,ui){
    alert('current: ' + $(ui.oldTab).attr('id'));
    return CheckSomething();

    }
});

Open in new window


Here is what I found so far:
cancel tab switch:  http://jsfiddle.net/nuywj/
get id of tab being selected:  http://jsfiddle.net/WnDV9/2/
beforeActivate:  http://api.jqueryui.com/tabs/#event-beforeActivate
0
Comment
Question by:KCTechNet
  • 5
  • 3
8 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39160250
Something like this
http://jsfiddle.net/WnDV9/95/
0
 

Author Comment

by:KCTechNet
ID: 39160530
That worked.  But why doesn't oldTab work? What is it's purpose?

Here is the 'final' version:
var currTab="#tabs-1";

var $tabs = $("#tabs").tabs({
    beforeActivate: function( evt, ui ) {
        var canContinue=true;
        if (1!=2){  //validation tests here
            alert('missing stuff for ' + currTab);
            canContinue == False; 
        }
            return canContinue
    },
    select: function( evt, ui ) {
        currTab=$(ui.tab).attr('href')
    }
})

Open in new window

0
 

Author Comment

by:KCTechNet
ID: 39161777
I noticed that I was using http://code.jquery.com/ui/1.10.3/jquery-ui.js", where your jsFiddle is using  1.9.2.  Your code wasn't working on my page until I changed mine to 1.9.2.  

But with either version, oldTab is undefined.
0
 
LVL 58

Expert Comment

by:Gary
ID: 39162034
Don't know, didn't bother with it because you wanted to perform an action before the tab change happens which means oldTab would be of no use anyway since it would be the previous tab after the change had already happened - if you understand me...
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:KCTechNet
ID: 39162299
But according to the documention (http://api.jqueryui.com/tabs/#event-beforeActivate), it says oldTab is the tab that is about to be deactivated, while newTab is the tab about to be activated.

Don't get me wrong, I appreciate your quick and accurate response, but being new to jQuery I am trying to understand as much as I can :)
0
 
LVL 58

Expert Comment

by:Gary
ID: 39162378
I'll be damned if I can get it work - it's always undefined.
0
 

Author Comment

by:KCTechNet
ID: 39162441
I have tried googling jquery tab oldTab undefined, but not getting anything good.
0
 

Author Comment

by:KCTechNet
ID: 39162876
I've got another open question regarding tabs if you have time:
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Jquery/Q_28126558.html
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now