How to have page remember tab after submital and make that tab active

Below is my html to remember the tab the the user was in after submittal and then return to that tab after submittal. It's not working. It always goes to the first tab. Why?

<html>
    <head>
        <title>Control.Tabs : Unobtrusive CSS Tabs for Prototype</title>    
        <link rel="stylesheet" href="http://livepipe.net/styles/screen.css"/>
        <script src="http://livepipe.net/scripts/prototype.js"></script>
        <script src="http://livepipe.net/downloads/object.event.1.0.0.js"></script>
        <script src="http://livepipe.net/downloads/control.tabs.2.0.0.RC2.js"></script>
    </head>
    <body>
        <br><br><br>
        <div id="outer_container">
         <div id="main">
            <ul id="tabs_example_one" class="subsection_tabs">
                <li><a href="#one">One</a></li>
                <li><a href="#two">Two</a></li>
                <li><a href="#three">Three</a></li>
            </ul>
            <div id="one"><p>First tab</p></div>
            <div id="two"><p>Second tab</p></div>
            <div id="three"><p>Third tab</p></div>
            <?php
                if( isset( $_POST['submit'] ) ) {                   
                    $activetab=$_POST['activetab'];
                    echo "Active tab = $activetab";
                }
                echo '<form id="myform" name="myform" method="post" action="' . $_SERVER['SCRIPT_NAME'] . '">';
                echo '<input type="text"   name="text"   value="some text">';
                echo '<input type="submit" name="submit" value="submit">';
            ?>
            <script>
                new Control.Tabs('tabs_example_one',{afterChange: function(new_container){document.getElementById('activetab').value=new_container.id;}});
                Control.Tabs.findByTabId('one').setActiveTab('<?php echo $activetab ?>');
            </script>
            <input type="hidden" name="activetab" id="activetab">
            </form>
        </div>
        </div>
    </body>
</html>

Posted January 23rd, 2008 at 7:22am by ugarit

One way this could work is to use the #tabname feature of Control.Tabs, but it would involve dynamically altering the form's action URL on submit so that the new page has the tabname selected.

Posted January 24th, 2008 at 6:48am by Synchro

but isn't this library supposed to be working as I attempted?

Posted January 28th, 2008 at 9:12am by

Figured out.

I moved

below the ?>

Posted January 29th, 2008 at 12:59pm by ugarit

Oops it didn't come across. Solution is to more the input type that's hidden above the script section

Posted January 29th, 2008 at 1:20pm by ugarit

Login or Register to Post