News:

Join the Facebook Fan Page.

Main Menu

Neat script

Started by NIAB, July 22, 2013, 12:01:08 AM

Previous topic - Next topic

NIAB

Hey guys,

I wanted it so my topTopics box on my front page (index) could show it by Views or by Replies, so I googled around and found this handy peice of code

Code ("Handy") Select

   $("id").click(function(){
    $("id").load('file');


The way I have used it is so when you click a link (which in this case I have both Views and Replies) It reloads a specified file within a set div id.

Here's how I have used it
Code ("So what") Select

?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("#Views").click(function(){
    $("#topTopic").load('Page Containing Views Stuff.php');;
  });
   $("#Replies").click(function(){
    $("#topTopic").load('Page Containing Replies Stuff.php');
  });
});
</script>
<?
<a id="Views">Views</a>
<a id="Replies"">Replies</a>';
echo'<div id="WhatsHot">';
ssi_topTopics('replies', '8', 'array');
echo'</div>';


All it does is make it so when you click either "Views" or "Replies", it loads in the requested file. Of course if you just want to change a small line of text, or html. you can simply use .text or .html rather than .load.

Make sure you have the <?php ?> tags included in the loaded file, or it just loads the text from it. As well as including your SSI file :)

I'm sure most of you have found other methods of doing this, I just thought it was great and wanted to share.

Enjoy

What mine looks like.


TheListener

NIAB would you like this to be moved to the Tips and Tricks board?

The Craw

Might also suggest a title that more accurately depicts the content of the post. "neat script" made me think it was a support question.

Biology Forums

Is this essentially AJAX-based?

Arantor

It's completely AJAX based. The use of .load() shows that.

Colin

The elegance of jQuery :)
"If everybody is thinking alike, then somebody is not thinking." - Gen. George S. Patton Jr.

Colin

kat

Quote from: Grumpy Old Sod on July 23, 2013, 07:15:20 PM
NIAB would you like this to be moved to the Tips and Tricks board?

Duly moved.

Biology Forums

I'm trying this myself, but I can't seem to get it to work. Could you provide the whole code?

Advertisement: