Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Random Text Display Using JavaScript

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 03-02-2010
Member
 
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.
Reply With Quote
  #2  
Old 03-02-2010
Member
 
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.
Reply With Quote
  #3  
Old 03-02-2010
Member
 
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.
Reply With Quote
  #4  
Old 03-02-2010
Member
 
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.
Reply With Quote
  #5  
Old 03-02-2010
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 10:16 PM.