It is currently Thu Mar 28, 2024 3:34 am



Reply to topic  [ 1 post ] 
javascript : faking ajax paging 
Author Message
Felix Rex
User avatar

Joined: Fri Mar 28, 2003 6:01 pm
Posts: 16646
Location: On a slope
Reply with quote
Post javascript : faking ajax paging
I'm developing yet another website for my company. It's all set up for nt authentication which unfortunately seems to break AJAX. However, I love the UI abilities of AJAX so I'm trying to work around the no-ajax functionality. It's an intranet so load times are quick so I'm being fairly successful.

Anyway, there's a part that shows news events. The page shows one news event (the most recent) and the has links at the top (<<< and >>>) that scroll to next/previous. Ordinarily I would've used ajax to dynamically load the appropriate article into the page, but since I can't I settled for javascript hiding / unhiding the different articles that were all preloaded.

basically the html looks like this (very simplified obviously)
Code:
<table><tr><td id='left'>&lt;&lt;&lt;</td><td id='right'>&gt;&gt;&gt;</td></tr></table>
<table id='0'><tr><td>Article 1</td></tr></table>
<table id='1' style='display: none;'><tr><td>Article 2</td></tr></table>
etc.etc.etc


initially the <<< part has no link and the >>> has a link that invokes a javascript function nextNews(1);

Then here's the javascript:
Code:
function nextNews(id){
   var left = document.getElementById('left');
   var right = document.getElementById('right');
   try{
      document.getElementById(id-1).style.display = 'none';
      left.innerHTML = "<a href='javascript: nextNews(" + (id-1) + ");' title='Previous news item'>&lt;&lt;&lt;</a>";
   }
   catch(e){
      left.innerHTML = "&lt;&lt;&lt;";
   }
   try{
      document.getElementById(id+1).style.display = 'none';
      right.innerHTML = "<a href='javascript: nextNews(" + (id+1) + ");' title='Next news item'>&gt;&gt;&gt;</a>";
   }
   catch(e){
      right.innerHTML = "&gt;&gt;&gt;";
   }
   document.getElementById(id).style.display = '';
}


Anyway, it's nothing earth shattering but I was very happy with it. This works in IE7 and Firefox.

_________________
They who can give up essential liberty to obtain a little temporary safety, deserve neither liberty nor safety.


Tue Sep 11, 2007 12:29 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware.