Results 1 to 3 of 3

Thread: help creating random text generator upon click

  1. #1
    Join Date
    Oct 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help creating random text generator upon click

    Hello everyone this is my first time posting here.

    I have a question I have been searching for the answer but haven't found it

    I am hoping I phrase this so it makes sense but I want to create a script for a page on my portfolio site that effectively when open has a sentence like " Hello my name is Chris Grover and ........." where the ......... upon being clicked say different things I program to put in there, so it randomizes lots of different phrase endings.

    My Q...what where how do I do this?

    I am learning php, js, css, etc at a beginners rate. So I know some of the language but not a lot, any help would be greatly appreciated. Thanks! -Chris

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    HTML Code:
    <script type="text/javascript">
    var randomize={
    aPhrases:[
    'he is Raymond Angana aka rangana',
    'Antarctica is the only continent without reptiles or snakes.',
    'I saw another gibberish',
    'I saw this script in DD Forums',
    'I saw another message' // Last phrase should not contain a comma
    ] // Initialize he phrase within the brackets
    init:function(){
    	var genNum=Math.floor(Math.random()*this.aPhrases.length); // Generate random number
    	document.getElementById('el').firstChild.nodeValue=this.aPhrases[genNum];
    	}
    };
    </script>
    <style type="text/css">
    #el{
    #font-weight:bold;
    font-family:Arial,tahoma,verdana;
    font-size:10pt;
    color:#f00;
    }
    </style>
    <p>
    Hello my name is Chris Grover and <span id="el">this is the default message</span>.
    </p>
    <input type="button" value="Randomize" onclick="randomize.init()">
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. #3
    Join Date
    Oct 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you I'm going to test this out right now.

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
  •