There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
audio blue screen boot bsod computer cpu crash dell desktop driver drivers error excel external hard drive firefox freezes freezing hard drive hardware hijackthis internet internet explorer itunes laptop mac malware motherboard mouse network networking outlook 2007 power printer problem ram router screen slow sound trojan usb virus vista vista 32-bit windows windows vista windows xp winxp wireless wmp
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Random messages in a text area... (HTML/JavaScript)


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
NameTooLong's Avatar
Computer Specs
Senior Member with 353 posts.
 
Join Date: Dec 2002
Location: California, USA
Experience: Advanced
09-Aug-2003, 05:25 PM #1
Random messages in a text area... (HTML/JavaScript)
I want to use this code to write to a text area with a button next to the text area to change the message.

Code:
<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's Avatar
Computer Specs
Distinguished Member with 17,888 posts.
 
Join Date: Jul 2001
Location: Mexico of the North, MN
Experience: Disenfranchised American Male
09-Aug-2003, 05:56 PM #2
Is this a question, problem or other?? Or are you just informing us that you are going to use this script.
NameTooLong's Avatar
Computer Specs
Senior Member with 353 posts.
 
Join Date: Dec 2002
Location: California, USA
Experience: Advanced
09-Aug-2003, 09:10 PM #3
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.
__________________
Say no to TCPA.
Rockn's Avatar
Computer Specs
Distinguished Member with 17,888 posts.
 
Join Date: Jul 2001
Location: Mexico of the North, MN
Experience: Disenfranchised American Male
09-Aug-2003, 09:19 PM #4
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's Avatar
Computer Specs
Senior Member with 353 posts.
 
Join Date: Dec 2002
Location: California, USA
Experience: Advanced
09-Aug-2003, 09:23 PM #5
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...
__________________
Say no to TCPA.
Rockn's Avatar
Computer Specs
Distinguished Member with 17,888 posts.
 
Join Date: Jul 2001
Location: Mexico of the North, MN
Experience: Disenfranchised American Male
09-Aug-2003, 09:27 PM #6
What code do you have so far with the textarea...could you post it?
NameTooLong's Avatar
Computer Specs
Senior Member with 353 posts.
 
Join Date: Dec 2002
Location: California, USA
Experience: Advanced
09-Aug-2003, 09:33 PM #7
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.
Code:
<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's Avatar
Computer Specs
Senior Member with 353 posts.
 
Join Date: Dec 2002
Location: California, USA
Experience: Advanced
10-Aug-2003, 02:49 AM #8
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!!!
Code:
<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's Avatar
Computer Specs
Distinguished Member with 17,888 posts.
 
Join Date: Jul 2001
Location: Mexico of the North, MN
Experience: Disenfranchised American Male
10-Aug-2003, 03:41 AM #9
You need an onClick event to update the textarea...
NameTooLong's Avatar
Computer Specs
Senior Member with 353 posts.
 
Join Date: Dec 2002
Location: California, USA
Experience: Advanced
10-Aug-2003, 04:21 AM #10
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 .
Code:
<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>
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 07:27 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.