how to remain an a tab when button is clicked

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • simon2x1
    New Member
    • Dec 2008
    • 123

    #1

    how to remain an a tab when button is clicked

    i have a CSS tab which is tab1 and tab2 and both are on the html page, in both tabs i have a submit button (<input type="submit" name="submit1"/>) on both. if i am in tab2 and i click submit i want it to remain in tab2 not to go back to tab1
    Code:
    <html>
     <head>
    <title></title>
     <link href="SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
    
    <script type="text/javascript" charset="utf-8"> 
    function show(div){
    document.getElementById(div).style.display='';
    }
    
    </script>
    </head>
    <body>
     <?php
     if (isset($_GET['page'])) {
     $pages = ($_GET['page']);
     } else {
     echo "page one";
     }
     ?>
      
     <ul class="TabbedPanelsTabGroup">
     <li class="TabbedPanelsTab" tabindex="0"  id="one" >Tab1</li>
     <li class="TabbedPanelsTab" tabindex="0"  id="two" >Tab2</li>
     </ul>
      
     <div class="TabbedPanelsContent">
     <div>
    <form action="home.html" method="post">
      <input type="submit" name="submit1"  value="Submit"   onclick="show('one')"/>
    </form>
     </div></div>
      
     <div class="TabbedPanelsContent">
     <div>
    <form action="home.html" method="post">
      <input type="submit" name="submit1"  value="Submit"   onclick="show('two')"/>
    </form>
    
     </div></div>
      
     </body>
     </html>
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    then you could either use AJAX-calls to avoid the page-reload or add a flag serverside to the page (could be a javascript-variable like: var startTab = 'tab2') and process it in the page's onload event.

    Comment

    • omerbutt
      Contributor
      • Nov 2006
      • 638

      #3
      or you can do the same but submit the values on a separate page and then return back to this page with a query string which could be checked to make any of those tab selected
      lets say form is submitted on the page2.php after doing your operations
      header('locatio n:orignal-page.php?tab=1' );

      and on the orignal-page.php check
      if(isset($_GET['tab']) && $_GET['tab']==1){
      //make your tab selected by either applying the css class or what ever you desire
      }


      regards,
      Omer Aslam

      Comment

      • simon2x1
        New Member
        • Dec 2008
        • 123

        #4
        i want it on the same page(home.php) but the tab2 which i am on and i click on submit inside tab2 on the samepage(home.p hp) don't forget should display the tab2 i am on and not to take me but to tab1

        Comment

        • omerbutt
          Contributor
          • Nov 2006
          • 638

          #5
          if you mean to say that you donot want to submit it on another page then it would be better to use AJAX other wise if the requirement is that after submitting the information you want to be back on the same tab then i have told you the solution it would work in the same way

          Comment

          • simon2x1
            New Member
            • Dec 2008
            • 123

            #6
            i am a newbie when it come to Ajax but if you say it is going to work the same way i need you to edit my code and let me see it

            Comment

            • simon2x1
              New Member
              • Dec 2008
              • 123

              #7
              This is what am trying to say, the tabs are on the same page not different pages am talking about the content of the tabs i want the content of tab2 to display when ever i click submit button(onclick) in the content of tab2 not to take me back to tab1.

              Comment

              • simon2x1
                New Member
                • Dec 2008
                • 123

                #8
                please am still waiting for my reply

                Comment

                Working...