Results 1 to 5 of 5

Thread: Random Text Display Using JavaScript

  1. #1
    Join Date
    Aug 2006
    Posts
    221

    Random Text Display Using JavaScript

    I have created a website for the shop. Now I have been told to do some changes into that. I have done the other changes but I am stuck at a place. They want me to do something that can display some random text (lucky draw) which would be useful for them. I have tried lot of things but not succeeded. I want to know how to display the random text using JavaScript. Please help me soon as I want to make the changes earlier as possible.!
    AMD Sempron 2800+ @ 2Ghz
    Asus A7V8X-LA
    120Gb Seagate barracuda 7200Rpm Ultra-ATA 100
    Elixir 512mb DDR Pc3200 (Soon 1Gb)
    Club 3D Radeon 9600 256Mb
    Lite-On Cd & Dvd writer combo
    IDE-Dvd drive
    400w Psu
    Windows Xp Pro Sp2
    Advent Wireless Mouse & Keyboard.

  2. #2
    Join Date
    Aug 2006
    Posts
    227

    Re: Random Text Display Using JavaScript

    You can download the application by which you can output random text script. The application like RanTex can be useful for you. An application RanTex will display a random quote or text block from a list of your choice. The text that you want to get displayed can contain the HTML code so you can make them interactive. The following are the features of it :
    • The quotes that you will be using can be hard-coded or listed in a separate file.
    • This application displays random quotes or text from a list of your choice.
    • You can display the random text by using the Javascript.
    I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame.

  3. #3
    Join Date
    Jul 2006
    Posts
    442

    Re: Random Text Display Using JavaScript

    You can create the JavaScript as I have did :
    Code:
    <script type=”text/javascript”>
           var Quotes =
        {
        getRandomQuote: function()
        {
        var quote = [];
        quote[0] = “Keep Smiling.”;
        quote[1] = “Good habits result from resisting temptation.”;
        quote[2] = “Never say No“;
        quote[3] = “Implementation begins with I.”;
        quote[4] = “If you bow at all, bow low.”;
        quote[5] = “Greet Everyone.”;
        quote[6] = “Never miss Opportunity.”;
        quote[7] = “Be not afraid of growing slowly, be afraid only of standing still.”;
        quote[8] = “Tit for Tat.”;
        quote[9] = “Believe in Good Things.”;
         
        var maxLength = quote.length;
        var position = Math.floor(Math.random() * maxLength);
        return Quotes.displayQuote(“quoteWrapper”, quote[position]);
        },
    
       displayQuote: function(ctl, quote)
        {
        ctl = document.getElementById(ctl);
        ctl.innerHTML = quote;
        }
    
        };
         
        Quotes.getRandomQuote();
         
        </script>
    "When they give you ruled paper, write the other way..." J.R.J.

  4. #4
    Join Date
    Mar 2008
    Posts
    672

    Re: Random Text Display Using JavaScript

    For displaying the random text using the JavaScript follow the steps :
    1. First you will have to initialize an array.
    2. Then you will have to store the text strings in that array.
    3. You will have to find the length of this array.
    4. For generating a random number, you will have to use the Math.random().
    5. You will have to use the index that has been generated randomly for retrieving a text string from the array.
    6. Then display that text through a document.write().

    you will have to go from these steps when you want to display random text using JavaScript.

  5. #5
    Join Date
    Mar 2008
    Posts
    349

    Re: Random Text Display Using JavaScript

    You can check the following coding for displaying the random text :
    Code:
    var text_st = new Array("Point1", "Point2", "Point3", 
    "Point4", "Point5", "Point6", "Point7", "Point8", 
    "Point9", "Point10");
    
    var l = text_st.length;
    
    var rnd_no = Math.floor(l*Math.random());
    
    alert(text_st[rnd_no]);
    By using the above script you will get the random number of text.

Similar Threads

  1. using javascript how to clear text area?
    By talia in forum Software Development
    Replies: 4
    Last Post: 03-02-2014, 04:26 PM
  2. Random text messages being received as all symbols
    By Honey Singh in forum Portable Devices
    Replies: 5
    Last Post: 26-09-2010, 06:32 AM
  3. Generate Random Text In Ms Word
    By Captain Carrot in forum Windows Software
    Replies: 6
    Last Post: 04-09-2010, 05:58 AM
  4. How to manipulate JavaScript text?
    By Juaquine in forum Software Development
    Replies: 4
    Last Post: 11-02-2010, 05:46 PM
  5. How to use "Math.random()" to generate a random number in JavaScript?
    By Silent~Kid in forum Software Development
    Replies: 5
    Last Post: 03-02-2010, 05:06 AM

Tags for this Thread

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
  •  
Page generated in 1,713,579,862.02675 seconds with 17 queries