954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

menu stops loading pages

<script src="http://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript"></script>

<script type="text/javascript"> 
$(document).ready(function() {

   $('#navlist li a').click(function(){		
			
	$('#navlist .current').removeClass('current');
	$(this).addClass('current');
        return false;		
   });		
		
});
</script>

<ul id="navlist">
   <li><a href="?p=home"  class="current">Home</a></li>
   <li><a href="?p=product">Our Products</a></li>  
   <li><a href="?p=enquiry">Enquiry</a></li>
   <li><a href="?p=contact">Contact Us</a></li>
   <li><a href="?p=about">About Us</a></li>
</ul>


<div id="content">
  <?php 
	require_once('config.php');
					
	$default = 'home';  
	$page = isset($_GET['p']) ? $_GET['p'] : $default; 
	  if (!file_exists($page.'.php'))    
             { 
	      $page = $default;  
	     } 
	include($page.'.php');
  ?>			
</div>


javascript is used to add and remove class of anchor tag.

Without javascript menu loads pages to content div but when script works it only add and remove class of anchor tag. It stops loading pages to content div.

vizz
Junior Poster
164 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

The links don't fire - you've hijacked them with a return false. Take it off.

BTW - this is a js issue not php.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

The links don't fire - you've hijacked them with a return false. Take it off.

BTW - this is a js issue not php.

Thanks.

I removed return false, links are working but now class is not added to new link which is clicked, it is "Home" permanently selected.

can you help me about this,

$('#navlist .current').removeClass('current');
  $(this).addClass('current');
vizz
Junior Poster
164 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

Well, of course. Once you click the link, the page is redirected, and Home is the one selected again. I think you should just use PHP to determine which class to highlight, instead of defaulting to Home.

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You