# Random messages in a text area... (HTML/JavaScript)



## NameTooLong (Dec 26, 2002)

I want to use this code to write to a text area with a button next to the text area to change the message.


```
<script type='text/javascript'>
function random_content(){
	var tip=new Array()

	tip[0]="Always use Amorer\'s Hammers to repair items\.\.\. it is much cheaper and helps you level up faster\."
	tip[1]="Go as long as you can without meditating\.\.\. you\'ll get attributes faster but won\'t get a high level\."
	tip[2]="Try not to use sources of fast travel \(e\.g\. Silt Strider\) and you will get more experience from kills along the way and just running\."
	tip[3]="If you want to kill someone... take something and wait until they hit you, it will be self-defense and you are only fined for theft\."
	tip[4]="Never store your items in a container\.\.\. some have owners and all items put in them will be considered stolen when removed\."
	tip[5]="The farther you fall\.\.\. the faster you level up in acrobatics\.\.\. unless\, of course\, you die\. \:\-\)"

	var rt=Math.floor(Math.random()*tip.length)

	document.write(tip[rt])
}
random_content()
</script>
```


----------



## Rockn (Jul 29, 2001)

Is this a question, problem or other?? Or are you just informing us that you are going to use this script.


----------



## NameTooLong (Dec 26, 2002)

Sorry, it was a question... I can get that script to write the message in a text area, but I can't add a button to redo the function... I don't want to refresh the page to just go to the next message like I currently have the button set. When I set a button to do the function everything else on the page dissapears.


----------



## Rockn (Jul 29, 2001)

You'll probably need to write another function to reload the last function to the textarea. Set the new function to fire with the onClick


----------



## NameTooLong (Dec 26, 2002)

I'm not familiar with writing functions... the original part of that script was taken from www.dynamicdrive.com (i think) and they don't seem to have anything like what I'm wanting... could you show me how to do it? Or at least get me going in the right direction...


----------



## Rockn (Jul 29, 2001)

What code do you have so far with the textarea...could you post it?


----------



## NameTooLong (Dec 26, 2002)

This is how I was able to use it by refreshing but as you can see, it is not the best way to do it.

```
<script type='text/javascript'>
function random_content(){
	var tip=new Array()

	tip[0]="Always use Amorer\'s Hammers to repair items\.\.\. it is much cheaper and helps you level up faster\."
	tip[1]="Go as long as you can without meditating\.\.\. you\'ll get attributes faster but won\'t get a high level\."
	tip[2]="Try not to use sources of fast travel \(e\.g\. Silt Strider\) and you will get more experience from kills along the way and just running\."
	tip[3]="If you want to kill someone... take something and wait until they hit you, it will be self-defense and you are only fined for theft\."
	tip[4]="Never store your items in a container\.\.\. some have owners and all items put in them will be considered stolen when removed\."
	tip[5]="The farther you fall\.\.\. the faster you level up in acrobatics\.\.\. unless\, of course\, you die\. \:\-\)"

	var rt=Math.floor(Math.random()*tip.length)

	document.write("<a href='javascript:location.reload()'>Next Tip</a><textarea cols='50' rows='5'>" + tip[rt] + "</textarea>")
}
random_content()
</script>
```


----------



## NameTooLong (Dec 26, 2002)

I finally got it to work, I used a script from www.hotscripts.com to figure out how to do it and then I did it!!!

```
<html>
<head>
<script type='text/javascript'>
  var tip=new Array()
  // "\" escapes the next character in the line.
  tip[0]="Always use Amorer\'s Hammers to repair items\.\.\. it is much cheaper and helps you level up faster\."
  tip[1]="Go as long as you can without meditating\.\.\. you\'ll get attributes faster but won\'t get a high level\."
  tip[2]="Try not to use sources of fast travel \(e\.g\. Silt Strider\) and you will get more experience from kills along the way and just running\."
  tip[3]="If you want to kill someone... take something and wait until they hit you, it will be self-defense and you are only fined for theft\."
  tip[4]="Never store your items in a container\.\.\. some have owners and all items put in them will be considered stolen when removed\."
  tip[5]="The farther you fall\.\.\. the faster you level up in acrobatics\.\.\. unless\, of course\, you die\. \:\-\)"

  

  function random_tips(){
  	var rt=Math.floor(Math.random()*tip.length)
  	document.randomform.randombox.value = tip[rt]
  }
  window.onload=random_tips
</script>
</head>
<body>
<form name='randomform'>
<textarea name='randombox' cols='50' rows='5'>
Random tips box
</textarea>
</form>
<a href='javascript:random_tips()'>Next Tip</a>
</body>
</html>
```


----------



## Rockn (Jul 29, 2001)

You need an onClick event to update the textarea...


----------



## NameTooLong (Dec 26, 2002)

Actually it worked fine with the javascript link, but now I have added a button instead of a link and I'm using text input instead of text area... JavaScript is so addicting .

```
<html>
  <head>
    <script type='text/javascript'>
      var tip=new Array()
      // "\" escapes the next character in the line.
      tip[0]="Always use Amorer\'s Hammers to repair items\.\.\. it is much cheaper and helps you level up faster\."
      tip[1]="Go as long as you can without meditating\.\.\. you\'ll get attributes faster but won\'t get a high level\."
      tip[2]="Try not to use sources of fast travel \(e\.g\. Silt Strider\) and you will get more experience from kills along the way and just running\."
      tip[3]="If you want to kill someone... take something and wait until they hit you, it will be self-defense and you are only fined for theft\."
      tip[4]="Never store your items in a container\.\.\. some have owners and all items put in them will be considered stolen when removed\."
      tip[5]="The farther you fall\.\.\. the faster you level up in acrobatics\.\.\. unless\, of course\, you die\. \:\-\)"

      function random_tips(){
      	var rt=Math.floor(Math.random()*tip.length)
      	document.randomform.randombox.value = tip[rt]
      }
      window.onload=random_tips
    </script>
  </head>

  <body>
    <form name='randomform'>
      <input type='text' name='randombox' value='You do not have JavaScript enabled, you cannot see the random tips.'>
      <input type='button' value='Next' onclick='random_tips()'>
    </form>
  </body>
</html>
```


----------

