Question

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");
});
Was it helpful?

Solution 3

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.

OTHER TIPS

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top