views:

242

answers:

3

I'm trying to select a particular tab section of a web page, on clicking a link on another page. I was suggested to use the location.hash function to select that particular anchor element of the tab and add the hash property in the href attribute of the first web page.

But the code doesn't work for me.I get the entire page,instead of the particular tab selected. Can some one help me out?

Here is the code. This is the link in the first web page. I want the Submitted tab of the second webpage to be selected. So I have added the id of that tab, #submitted to the url.

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

This is the code of the second page,where I check if location.hash equals submitted.

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

$('#submitted , #formStatusSubmitted').click({
 <?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");
});
+1  A: 

try window.location.hash or document.location.hash

DroidIn.net
yeah.. I tried both,it still doesn't show that tab alone.
Angeline Aarthi
+1  A: 

Looks to me like you fire off the click() before you set the handler for click. Try moving $("#submitted").trigger("click"); to the bottom.

JasonWoof
It is at the bottom of the javascript code
Angeline Aarthi
it's the 2nd line of the code you posted. _before_ where you set the click handler (most of the rest of the code you posted)
JasonWoof
A: 

I found the solution to my problem. I just added a # to the Id in that if condition, that is,

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

and it works now..If I clink on that particular link, I get redirected to that particular tab section.

Angeline Aarthi