ny su ny su - 6 months ago 15
jQuery Question

get active tab name into a hidden field at runtime

I have aspx page with tabs like below...

<ul class="tabs-menu" style="list-style-type: none;" >
<li class="active"><a class="anchor" href="#ATab" style="text-decoration: none;" > A</a></li>
<li><a class="anchor" href="#BTab" style="text-decoration: none;">B</a></li>
<li><a class="anchor" href="#CTab" style="text-decoration:none;">C</a></li>

</ul>


This is the hidden field that should store the active tab and pass it to a function when clicked on submit button on Modal popup

<input type="hidden" name="findTab" id="findTabname" value=""/>


I am showing this ASPX page as Modal pop up from another page using Jquery like below

$("#Test").live('click', function OpenSearchDialog() {
$("#dialog_testsearch").load("Test.aspx", function() {
$(this).dialog({
autoOpen: true,
modal: true,
width: 750,
buttons: {
Go: function() {
var current_tab = $("#anchor").tabs('option', 'selected');
//anchor is my class for the list items
callTestFunction()

},
Close: function() {
$(this).dialog("close");
}
}
});
$(this).siblings('.ui-dialog-titlebar').remove();
$(this).container.css('height', 'auto');
});
return false;
});


Now My question is how do I get the name of active name into that hidden field ? And then into this Jquery when clicked on Go button..
Because I wanted to execute functions based on tabs selected

function callTestFunction()
{
if A
//do this
if B
//do this
if c
//do this
}


I am really hitting my head to the wall to this simple thing. But I couldn't get it working

Prs Prs
Answer

Try it..

$('button').on('click', function(){
   $('#findTabname').val($('.tabs-menu li').index('.active'));
})

And when you want to use the value of the hidden input to active tabs back use..

$('.nav-tabs li:eq($('#findTabname').val()) a').tab('show');
Comments