?
Solved

get id of current tab, beforeActivate

Posted on 2013-05-12
8
Medium Priority
?
4,150 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 2000 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
More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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 discusses how to create an extensible mechanism for linked drop downs.
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…
Suggested Courses

777 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