views:

69

answers:

2

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?

+2  A: 

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.

Jan Jongboom
You have given the right answer in the first case and I missed out the # while checking the condition if(document.location.hash=="#submitted") and didn't get the answer. Only now figured out my mistake..
Angeline Aarthi
+1  A: 

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>
peirix
I tried this,but I still don't get the answer. I did an alert inside the if(location.hash) block, the alert didn't pop up..
Angeline Aarthi
the `location.hash` might return the string including the actual hashkey. Have you tried just: `alert(location.hash)` to see what the output is?
peirix
Yes I figured this out after a long time. The if condition matches only if I give #submitted. But Jan had suggested it rightly.. Only I didn't notice properly..
Angeline Aarthi