Results 1 to 4 of 4

Thread: Need help with basic Javascript thing

  1. #1

    Thread Starter
    Registered User
    Join Date
    Aug 2003
    Posts
    2

    Need help with basic Javascript thing

    I want to put a script on an HTML page that will show up a random text or number from a list.

    Like, whenever I reload the page, a random text appears on the page or something like that.

    Thanks

  2. #2
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    Something like this should work. It could probably be cleaned up a bit, but you should be able to get the picture. Just copy and past the code into a new HTML file to give it a try:

    Code:
    <script langauge="JavaScript">
    var aList = new Array();
    var ALC = 0;
    
    aList[ALC++] = "I Feel Great"
    aList[ALC++] = "I Feel Sick"
    aList[ALC++] = "I Feel Stupid"
    
    function ShowRndMsg(){
    var sMsg
    var iRnd = Math.round(Math.random() * (ALC-1))
    
    sMsg = aList[iRnd];
    return sMsg;
    
    }
    
    </script>
    
    This is some test text<br><br>
    
    <script language="JavaScript">
    document.writeln("How I Feel:  <b>" + ShowRndMsg() + "</b>");
    </script>
    
    <br><br>
    This is some more test text.
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

  3. #3

    Thread Starter
    Registered User
    Join Date
    Aug 2003
    Posts
    2
    Thanks a lot man

  4. #4
    Fanatic Member RealisticGraphics's Avatar
    Join Date
    Jul 1999
    Location
    Arkansas
    Posts
    655
    No Problem
    www.RealisticGraphics.net

    Running VS.Net Enterprise & VB 6

    Other Languages: JavaScript, VBScript, VBA, HTML, CSS, ASP, SQL, XML

    MSN Messenger: kmsheff

Posting Permissions

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



Click Here to Expand Forum to Full Width