Solved

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

Posted on 2015-01-27
4
424 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

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.

Question has a verified solution.

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

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

839 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