Solved

get id of current tab, beforeActivate

Posted on 2013-05-12
8
4,033 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
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.

 
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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

786 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