1

I'm using tabs, but wondering if it's possible to "refresh" tab content onclick?

2
  • 2
    What is the content of the tab? How is it changing? Commented May 24, 2010 at 14:46
  • If it's a div, what's there to populate? If it's ajax, that's about as 'refreshed' as you get... Commented May 24, 2010 at 14:49

4 Answers 4

4

here's how i do it with ajax in asp.net mvc:

<div id="content">
    <ul>
        <li><a href="#tab0"><span>Details</span></a></li>
        <li><a href="#tab1"><span>Cost</span></a></li>
        <li><a href="#tab2"><span>Bookings</span></a></li>
    </ul>
    <div id="tab0"></div>
    <div id="tab1"></div>
    <div id="tab2"></div>
</div>

<script type="text/javascript">
    $(document).ready(function() {
        $(function() {
            var $tabs = $("#content").tabs({
                select: function(e, ui) {
                    var thistab = ui;
                    runMethod(thistab.index);
                }
            });
        });
    });

    function runMethod(tabindex) {
        switch (tabindex) {
            case 0:
                getTabZeroData();
                break;

            case 1:
                getTabOneData();
                break;

            case 2:
                getTabTwoData();
                break;
        }
    }
</script>

<script type="text/javascript">
// ajax getTabnnn methods here...
</script>

each of the getTabnnnData methods runs it's own little ajax routine and the div is populated. This is quite effective as you can also get a little clever and only run the method if the target div is still empty etc..

hope that gives another slant on things.

jim

Sign up to request clarification or add additional context in comments.

Comments

0

Yes it is possible, but you dont need onClick event for this I think

use this

<div id="example">
     <ul>
         <li><a href="ajaxpage1.php"><span>Content 1</span></a></li>
         <li><a href="ajaxpage2.php"><span>Content 2</span></a></li>
         <li><a href="ajaxpage3.php"><span>Content 3</span></a></li>
     </ul>
</div>

Notice that: instead of giving the id of the tab's division, a page link given so every time you click on the tabs, it updates it

this degrades gracefully - the links, e.g. the content, will still be accessible with JavaScript disabled.

ps: I am assuming that you having a working tabs

Comments

0

Please understand that it is very likely not the best way to do this. But this is what he asked for.

function tabrefresh(){
    $( "#tabs" ).tabs( "refresh" );
};

<button onclick="tabrefresh()">Refresh Tabs</button>

Comments

-1

Simple: http://docs.jquery.com/UI/Tabs

;)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.