Solved

How to get a form's ID for the selected jquery ui tab?

Posted on 2015-01-27
4
407 Views
Last Modified: 2015-02-02
Experts,

I have a jquery ui tab instance with several tabs. Each tab has a form with unique ID.

The following determines which jquery ui tab is selected:
var active = $("#tabs").tabs("option","active");

If a user clicks from tab 1 to tab 2, I need to be able to get the ID of the form on the selected tab.

The following attempts to get the <form> ID but only grabs the ID belonging to the first form on the first tab.

var form_id = $("form").attr('id');

If the user selects the second tab, I need to be able to identify the form's ID on this tab?

Thanks for the help!
0
Comment
Question by:evibesmusic
  • 2
4 Comments
 
LVL 44

Expert Comment

by:Rainer Jeschor
ID: 40574136
Hi,
sorry i am on the road therefore no live example but a combination of your first line of code to get the active tab and then using this element as scope for the second selector:
var form_id = $("form",active).attr('id');
HTH
Rainer
0
 

Author Comment

by:evibesmusic
ID: 40574143
@Rainer Jeschor:

Thanks for the suggested code.

Using your suggestion the following code results in an alert that says "undefined" when viewing any other tab other than the first. It does successfully return the ID of the form on the first tab but, not when viewing any other tab.

var active = $("#tabs").tabs("option","active");
//GET ID OF FORM BEING SUBMITTED
var form_id = $("form",active).attr('id');
alert(form_id);
return false;
0
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 40584398
Hey evibesmusic,

Your 'active' variable will not contain the actual tab, only a zero-based index (integer) of the selected tab, so you can't use that to filter the content. You'll need to use that index to get a reference to the actual tab content:

var active = $("#tabs").tabs("option","active"); //returns the index of the selected tab
var tab = $('#tabs .ui-tabs-panel').tabs()[active]; // uses the index to get the content of the active Tab
var formid = $("form",tab).attr('id'); // now you can filter the form from the content of the active tab

Open in new window

0
 

Author Closing Comment

by:evibesmusic
ID: 40585498
@Chris Stanyon:

Perfect! Thank you very much. Works as intended.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
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…

862 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

Need Help in Real-Time?

Connect with top rated Experts

30 Experts available now in Live!

Get 1:1 Help Now