Solved

get id of current tab, beforeActivate

Posted on 2013-05-12
8
4,120 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
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 how to dynamically set the form action using jQuery.
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)

717 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