zarino wrote:
Server-side coding would be nice, but it's not PHP-enabled, and I
think the only method would through ASP which I, frankly, haven't the
foggiest clue about! For the time it'll take to download the
relatively small number of 'facts', it shouldn't be a problem.

Wasted bandwidth!  Tsk, tsk!  :-)

For small amounts of data, it's certainly not a big deal. Then you are left with two straightforward techniques, and one trickier option.

----------
The first one is relatively obnoxious unless you have access to *some* dynamic method on the server. (Do you have SSI available?) This would be to have the divs included on each page, but hidden with some combination of CSS and JS, then to use JS to display the randomly selected one.

Pros: Leaves the HTML formating inside HTML
      Easy to implement
Cons: Large maintenance issue unless you have some dynamic include
      Increased bandwidth

----------
The second one is to do the HTML formating from Javascript. Download a JSON array with all your "facts", randomly, choose one, and format HTML from it to add to the DOM.

Pros: Pretty easy to implement
      Centralized maintenance of your facts
Cons: Less flexibility in HTML facts, as they're created by static code.


----------
The trickier one involves AJAX: format each fact in its own HTML file, and maintain a simple JSON list of filenames. At load time, randomly select one element from the list, and AJAX it into the DOM.

Pros: Leaves the HTML formating inside HTML
      Centralized maintenance of your facts
Cons: More complex to implement

This one is not that hard. If you would like your facts to have some simple flexibility in layout and design, I would recommend it. Here's some pseudo-code:

// in facts.js:
var facts = ["factA", "factB", "factC", "brandNewFact", "faceTheFacts"];

// in a script included after facts.js:
$(document).ready(function() {
    var fact = facts[Math.floor(facts.size * Math.random())];
    $("#factHolder").load("/path/to/fact/dir/" + fact + ".html");
});

Adding a new fact involves creating an HTML snippet in a file and updating the list in facts.js. You can delete one by simply updating facts.js.

Cheers,

  -- Scott


I take it, using your code, Glen, I'd have a series of hidden divs and
then jQuery will randomly pick one and show it?

This, I presume, will require all of the divs to be duplicated in all
of the pages I want to have a random fact displaying on? Is there a
way to have the 'facts' centralised -- for example in the jQuery
'custom.js' file or something -- so it's easy to add and remove new or
old facts?

Thanks for your imput. We've nearly cracked it! :-D

Zarino



On Jun 26, 11:07 pm, "Glen Lipka" <[EMAIL PROTECTED]> wrote:
I agree.  I was stretching his original intent. :)

Glen

On 6/26/07, Scott Sauyet <[EMAIL PROTECTED]> wrote:



Glen Lipka wrote:
Scott, I can think of a couple reasons for this.
Let's say you want to scroll some facts or quotes or customer
testamonials across the screen, but you also want to start at a random one.
That sort of thing.   Or scrolling images.
Oh, I can see plenty of reasons for choosing a random element of a set,
but the OP said
I'd like to create a repository of 'facts' and have jQuery serve up
a different fact at random with each page-load.
which sounds more server-side to me.  Not a big deal either way.  As you
pointed out, it's easy enough to do in JQuery if that's what's needed.
   -- Scott





Reply via email to