Alternating Text Script?

Discussion in 'JavaScript' started by movidalatina, Jun 14, 2009.

  1. #1
    Im needing a script (Javascript I think) that can display alternating text.

    there is a javascript for displaying random
    images
    , but I need to display random text.

    anyone? or will this have to be php?
    any suggestions or ideas?

    thanks
     
    movidalatina, Jun 14, 2009 IP
  2. James Barcellano

    James Barcellano Active Member

    Messages:
    114
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #2
    I would do this in php, but you can modify that script to use text instead

    
    <html>
    <head>
    <script type="text/javascript">
    // ==============================================
    // Copyright 2003 by jsCode.com
    // Source: jsCode.com
    // Author: etLux
    // Free for all; but please leave in the header.
    // Changed By James Barcellano
    // ==============================================
    
    // Set up the image files to be used.
    var theText = new Array() // do not change this
    // To add more image files, continue with the
    // pattern below, adding to the array. Rememeber
    // to increment the theImages[x] index!
    
    theText[0] = 'Phrase 0'
    theText[1] = 'Phrase 1'
    theText[2] = 'Phrase 2'
    theText[3] = 'Phrase 3'
    theText[4] = 'Phrase 4'
    
    // ======================================
    // do not change anything below this line
    // ======================================
    
    var j = 0
    var p = theText.length;
    
    var preBuffer = new Array()
    for (i = 0; i < p; i++){
       preBuffer[i] = new Image()
       preBuffer[i].src = theText[i]
    }
    
    var whichText = Math.round(Math.random()*(p-1));
    function showText(){
    document.write('<span>' + theText[whichText] + '</span>');
    }
    </script>
    </head>
    <body>
    Random text : <script type="text/javascript">showText();</script>
    </body>
    </html>
    
    HTML:
    Tested and works.
     
    James Barcellano, Jun 14, 2009 IP
  3. movidalatina

    movidalatina Well-Known Member

    Messages:
    1,268
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Ahhhh excellent work James.. I tried it and it works..Niceeee
    Thanks
     
    movidalatina, Jun 14, 2009 IP