I have the following HTML which I have applied Jquery tabs to:
<div id="lineitems">
<ul>
<li><a href="#not-issued" onClick="displayItems()">Not Issued</a></li>
<li><a href="#issued" onClick="displayItems()">Issued</a></li>
<li><a href="#search" onClick="displayItems()">Search</a></li>
</ul>
<div id="not-issued">Not Issued Items</div>
<div id="issued">Issued Items</div>
<div id="search">Search for items</div>
</div>
I have the following jQuery function which does what it's supposed to, it will return "issued" when you click on the issued tab etc.
$("#lineitems").tabs({
beforeActivate: function (event, ui) {
var issued = ui.newPanel.attr('id'); //Get newly selected tab
alert(issued);
}
});
alert(issued);
The first alert
correctly returns "issued" or whatever tab is selected, however the second alert
returns [object htmldivelement]
. I'm not sure why it isn't returning the same value. What am I doing wrong?
To put it into context, I'm trying to get the value of the selected tab so I can change the value of the submit button accordingly and then pass the value (of the selected tab) to an ajax function.
I have also tried using:
$("#lineitems").bind("tabsactivate", function(event, ui) {
issued = ui.newTab.index();
alert(issued);
});
But again I run into the same problem that the issued variable returns empty outside of the function.
EDIT: Using Bhushan Kawadkar's answer I got it working, I also had to change issued
to a string using toString()
to pass it to the Ajax function correctly.
I also followed T J's suggestion and removed the onClick event from my links as they're not needed, as the function is called every time a new tab is clicked anyway.