PDA

View Full Version : help creating random text generator upon click



shapescolors
10-24-2008, 02:46 AM
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

rangana
10-24-2008, 06:56 AM
<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()">

shapescolors
10-26-2008, 11:01 AM
Thank you I'm going to test this out right now.