Solved

get id of current tab, beforeActivate

Posted on 2013-05-12
8
4,057 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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
 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Html Table looping 4 25
jQuery Dialog Autoresize Bug 2 24
IFrame in MVC 2 23
Html Newline 7 20
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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

839 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