Angeline
Angeline

Reputation: 2379

How to link to a tabbed section of another page?

I have a webpage and if I click a link in the page, it should be redirected to a particular tab of another url. That is, I have a link called 'Submitted' in my home page. If I click that link, it show display the 'Submitted' tab of the view page. Is this possible?

$status="Submitted";
<a id="formStatus<?php echo $status;?>" class="code_link" href="/FormBuilder/main/viewAllMyForms"><?php echo $status;?></a>

In my viewAllMyForms page, I have a tab section like

<ul id="sort_by" class="horizontal_navigation float_left">
   <span class="showfilter">Show:</span>
        <li> <a id="all"  class="selected" href="#">All</a></li>
        <li> <a id="drafted"  href="#">Drafts</a></li>
        <li> <a id="submitted"  class="last" href="#">Submitted</a></li>
</ul>

In my script I have the below code, so that when I click the Submitted tab in my viewAllMyForms page, only the forms with status "Submitted" are displayed.

$('#submitted , #formStatusSubmitted').click(function(){

<?php foreach($myForms as $form):
  if($form['Form']['status']=="Incompleted"){ ?>
    $('.fm_myformsample_container'+<?php echo $form['Form']['id'];?>).hide();
<?php }

 else{?>
   $('.fm_myformsample_container'+<?php echo $form['Form']['id'];?>).show();
<?php }
endforeach;?>
$('#sort_by').find(".selected").removeClass();
$('#submitted').addClass("selected");
});

So When I click the "submitted" link in the home page, how to connect it to the "Submitted" link in the viewAllMyForms page?

Upvotes: 1

Views: 509

Answers (2)

peirix
peirix

Reputation: 37751

I'm not entirely sure on what you're asking, but if you want to trigger the click event that you made for your tabs, then you could use jQuery trigger with the hash tag, as suggested by Jan:

if (location.hash == "submitted") {
    $("#submitted").trigger("click");
}

And then set up your link to include a hashtag:

<a id="formStatus<?php echo $status;?>" class="code_link" 
   href="/FormBuilder/main/viewAllMyForms#submitted"><?php echo $status;?></a>

Upvotes: 1

Jan Jongboom
Jan Jongboom

Reputation: 27313

You should redirect from the first page to secondpage.html#submitted

In JavaScript you check in the $(document).ready() of the secondpage.html if there is a hashtag available thru

document.location.hash

and if there is '#submitted', you show the submitted part of your page.

Upvotes: 2

Related Questions