SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Mar 2010
    Location
    UK
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Refreshing random content

    What would be the jQuery-based way of refreshing random content that is currently managed by PHP?

    PHP Code:
    $num Rand (1,5);
    switch (
    $num) {
    case 
    1:
    echo 
    '<div>Random content</div>';
    break;
    // and so on...

    I'd like to add the option to refresh this content with jQuery. I'm not sure how this might work (I'm only an amateur coder and not familiar with JS beyond using plugins). Would it be as simple as adding an ID to each div and then somehow displaying a new div at each click of an anchor? It doesn't really need to be random: in number order would be fine. I want to keep the underlying PHP method, or a near equivalent, so that it degrades nicely.

  2. #2
    SitePoint Zealot Gar onn's Avatar
    Join Date
    Feb 2011
    Location
    Belgium
    Posts
    130
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    make a button that calls a function that dos wan of the things described here:

    If you fave few ranom contents (witch are not long):
    put the values in an array and call a random one with ath.round(Math.random()*number_of_contents)

    Or you could make a div for each random content and than use jQuery's hide and show to show and hide the content. and use jQuery(".random_content_div").get(int) where "int" is a random integer to get a random element to show up.

    If you have manny random contents
    Use ajax to get your content from a PHP script


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •