Dynamically Changing jQuery UI Accordion Tab Headings

If you're into using jQuery UI (and who's not?) then this is an easy way to change the heading of a jQuery accordion tab style heading to reflect user focus.

So first off, we have a nav panel and a center panel in our app pictured below. Basically when a user clicks on one of the Job Step links on the left, we are reloading pages into the center area's accordion to update content based on what the user selected using jQuery load(), but we also want to update the header of the accordion to reflect their selection in real-time. Lucky for us, this is very simple with jQuery. So for starters let's take a look at the structure of the accordion and tab elements...
view plain print about
1$(function() {
2        $("#accordion").accordion();
3    });
4
5
6            <div id="accordion">
7                <h3><a id="inputHeader" href="##">Input</a></h3>
8                <div id="stepInput" style="height:340px;">
9                    <p></p>
10                </div>
11
12                <h3><a id="outputHeader" href="##">Output</a></h3>
13                <div id="stepOutput" style="height:340px;">
14                    <p></p>
15                </div>    
16            </div>
The accordion is basically referenced as a div and each of the tabs have a header (h3 in this case) selector to control the label text of each tab. The divs labeled stepInput and stepOutput are explicitly named for my project and I have javascript/jQuery functions that dynamically load content via cfm pages into these divs. So out of the gate our headings just read "Input" and "Output", but we want to change the headings based on what a user selects - so here's how. Basically, all we have to do is call a js function when a user clicks on one of our nav links (pictured top left in our photo above). Once that happens, we call this simple js function which uses arguments from the nav link that the user clicked on (the links were dynamically built by cflooping through a query).
view plain print about
1reloadStepInput = function(jobID, jobDetailID, stepNo, systemCode, entryMode){
2        $("#stepInput").load('jobjournalinput.cfm?jobID=' + jobID + '&jobDetailID=' + jobDetailID + '&stepNo=' + stepNo + '&systemCode=' + systemCode + '&entryMode=' + entryMode);
3        $("#inputHeader").text('Input - Step No. ' + stepNo + ' / System ' + systemCode + ' / ' + '<cfoutput>#jobNo#</cfoutput>');
4    }
So that was pretty simple right? We just used a plain old $("#myElementName").text(myArgValues); to dynamically update the h3's header text for the tab. Simple, easy, effective - that's what jQuery and ColdFusion are all about!

Related Blog Entries

Comments
batterie's Gravatar They are very informative.
# Posted By batterie | 7/20/10 8:54 AM
labatterie's Gravatar I 've also discovered recently one more source of information.
# Posted By labatterie | 7/20/10 8:54 AM
NFLjerseys's Gravatar If [url=http://www.nfljerseys-shopping.com/]NFL jerseys[/url] and [url=http://www.nfljerseys-shopping.com/]football jerseys[/url] are your favorite, nfljerseys-shopping.com can be your good choice as it supply many [url=http://www.nfljerseys-shopping.com/]cheap jerseys[/url].
# Posted By NFLjerseys | 7/27/10 12:16 AM
Monster Energy Team Cap's Gravatar There are so many reasons choosing prowantgo.
In the first place,accept paypal and transfer.Second,Lowest pricewith High quality.And we are waiting for you in here:http://www.prowantgo.net/
# Posted By Monster Energy Team Cap | 7/27/10 10:48 AM
ciphone's Gravatar Hello!everyone!iphone is so expensive.so I like <a href=" www.efox-shop.com/index.php/cPath/5_35
" rel="nofollow"> Ciphone </a>. d^_^bIt is very interesting.I want to introduce <a href="http://www.efox-shop.com/"; rel="nofollow"> efox-shop</a> to you.
# Posted By ciphone | 7/30/10 11:25 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.5.007. Contact Blog Owner