There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Web Design & Development
Tag Cloud
access acer asus bios bsod computer crash drive driver drivers error ethernet excel freeze games gaming hard drive hardware hdmi internet java laptop malware memory monitor motherboard music network obp printer problem ram random registry router slow software sound trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Scope issues in a new JS

Reply  
Thread Tools
MetricJester's Avatar
Computer Specs
Junior Member with 6 posts.
 
Join Date: Sep 2009
Experience: Advanced
06-Sep-2009, 03:07 AM #1
Scope issues in a new JS
Code:
<html>
<HEAD>

<Script language="text/JavaScript">
// Random message spouter  - Spout a message

if(!TRUE) {const FALSE = 0; const TRUE = !FALSE;};

var msg = new Array();
msg[1]= "7th Legion";
msg[2]= "Alone in the Dark (1992)";
msg[3]= "America's Army";
msg[4]= "American McGee's Alice";
msg[5]= "Anarchy Online";
msg[6]= "Asheron's Call 2: Fallen Kings";
msg[7]= "BioShock";
msg[8]= "The Black Mirror";
msg[9]= "Blade Runner";
msg[10]= "Blair Witch Volume 1: Rustin Parr";
msg[11]= "Blair Witch Volume 2: The Legend of Coffin Rock";
msg[12]= "Blair Witch Volume 3: The Elly Kedward Tale";
msg[13]= "Carmageddon";
msg[14]= "Carmageddon 2: Carpocalypse Now";
msg[15]= "Carmageddon 3: TDR 2000";
msg[16]= "Carmageddon Splat Pack";
msg[17]= "Chrono Cross";
msg[18]= "Clive Barker's Jericho";
msg[19]= "Command & Conquer 3: Kane's Wrath";
msg[20]= "Command & Conquer 3: Tiberium Wars";
msg[21]= "Command & Conquer The First Decade";
msg[22]= "Dark Reign: The Future of War";
msg[23]= "Deadly Tide";
msg[24]= "Delta Force 2";
msg[25]= "Descent";
msg[26]= "Deus Ex";
msg[27]= "Diablo";
msg[28]= "Diablo II: Lord of Destruction";
msg[29]= "Die Hard Trilogy";
msg[30]= "Dirge of Cerberus: Final Fantasy VII";
msg[31]= "Doom 3";
msg[32]= "Doom 3: Resurrection of Evil";
msg[33]= "Duke Nukem 3D";
msg[34]= "Duke Nukem II";
msg[35]= "Duke Nukem: Manhattan Project";
msg[36]= "Dungeon Keeper 2";
msg[37]= "Earth & Beyond";
msg[38]= "Fable: The Lost Chapters";
msg[39]= "Final Fantasy Chronicles";
msg[40]= "Final Fantasy IX";
msg[41]= "Final Fantasy Origins";
msg[42]= "Final Fantasy VII";
msg[43]= "Final Fantasy VIII";
msg[44]= "Final Fantasy X";
msg[45]= "Final Fantasy X-2";
msg[46]= "The Forgotten";
msg[47]= "Frankenstein: Through the Eyes of the Monster";
msg[48]= "From Dusk Till Dawn";
msg[49]= "Giants: Citizen Kabuto";
msg[50]= "God of war";
msg[51]= "God of war 2";
msg[52]= "Hard Truck 2";
msg[53]= "Hitman Trilogy";
msg[54]= "The House of the Dead";
msg[55]= "Interstate '76";
msg[56]= "The Journeyman Project 3: Legacy of Time";
msg[57]= "Jumpgate: The Reconstruction Initiative";
msg[58]= "KKND Xtreme";
msg[59]= "King's Quest I: Quest For The Crown (1990)";
msg[60]= "Legacy of Kain: Defiance";
msg[61]= "Lineage: The Blood Pledge";
msg[62]= "The Longest Journey";
msg[63]= "Lost Planet: Extreme Condition";
msg[64]= "MDK";
msg[65]= "MDK 2";
msg[66]= "The Maw";
msg[67]= "MechCommander";
msg[68]= "Metal Gear Solid";
msg[69]= "Metal Gear Solid 2: Sons of Liberty";
msg[70]= "Metal Gear Solid 3: Snake Eater";
msg[71]= "Microsoft Golf 1998 Edition";
msg[72]= "Monster Truck Madness";
msg[73]= "Mortal Kombat: Deception";
msg[74]= "Myst";
msg[75]= "Myst III: Exile";
msg[76]= "Myst IV: Revelation";
msg[77]= "Myst V: End of Ages";
msg[78]= "Myth: The Fallen Lords";
msg[79]= "The Need for Speed";
msg[80]= "Need for Speed III: Hot Pursuit";
msg[81]= "The New Adventures of the Time Machine";
msg[82]= "Nibiru: Age of Secrets";
msg[83]= "Oddworld: Abe's Exoddus";
msg[84]= "Parasite Eve";
msg[85]= "Populous: The Beginning";
msg[86]= "Quake II";
msg[87]= "Quake Mission Pack No. 1: Scourge of Armagon";
msg[88]= "Quake Mission Pack No. 2: Dissolution of Eternity";
msg[89]= "Riven: The Sequel to Myst";
msg[90]= "The Secret of Monkey Island";
msg[91]= "SiN";
msg[92]= "SiN Episodes: Emergence";
msg[93]= "SimCoaster";
msg[94]= "The Sims Online";
msg[95]= "Soldier of Fortune: Platinum Edition";
msg[96]= "Sonic Mega Collection Plus";
msg[97]= "Star Trek: Starfleet Command";
msg[98]= "Street Fighter Alpha";
msg[99]= "Tachyon: The Fringe";
msg[100]= "Terminal Velocity";
msg[101]= "Tomb Raider: The Last Revelation";
msg[102]= "Total Annihilation";
msg[103]= "Traitors Gate";
msg[104]= "Ultima I: The First Age of Darkness";
msg[105]= "Ultima Online: Renaissance";
msg[106]= "Ultima Online: Age of Shadows";
msg[107]= "Ultima Underworld: The Stygian Abyss";
msg[108]= "Vampire: The Masquerade - Redemption";
msg[109]= "Warcraft II: Beyond the Dark Portal";
msg[110]= "Wing Commander";
msg[111]= "The Witcher Enhanced EditionWolfenstein 3D";
msg[112]= "X-COM: UFO Defense";
msg[113]= "XS";

function spout_message()
{
	var i = Math.round(200*Math.random()); 
	spout_out.value=msg[i];
}

</script>
</head><body>

<form>
<input type="button" onClick="spout_message()" id="spout_btn" name="spout_btn" value="spout">
<input type="text" id="spout_out" name="spout_out" value="Spout out a name">

</form>
</body>
</html>
now that you've seen my code, can you help me out? no matter what browser I use I can't seem to get that pesky onClick to work. It's supposed to send a random message to the value of the edit box. I know this isn't sloppy code, and it looks like it really should work, but there's function call problems. Error says "spout_message is not defined" same on Chrome and Firefox. I'm not going to go and try a sloppy browser like IE, just need the thing to work.
MMJ's Avatar
MMJ MMJ is offline
Senior Member with 3,637 posts.
 
Join Date: Oct 2006
06-Sep-2009, 04:28 AM #2
Change

<Script language="text/JavaScript">

to

<script type="text/javascript">

And yeah, that code isn't too great. Building an array like that isn't too wise. And your array randomizer doesn't work right.
MetricJester's Avatar
Computer Specs
Junior Member with 6 posts.
 
Join Date: Sep 2009
Experience: Advanced
06-Sep-2009, 05:24 AM #3
I'm an old QBasic user, and this was just supposed to be a quick little script for a friend who doesn't understand JavaScript. I wanted him to be able to add messages on his own. And what's wrong with the Qbasic style randomizer shortcut (besides that it rounds up 200 times a random number)? I looked around w3schools.com and couldn't find anything better.
MetricJester's Avatar
Computer Specs
Junior Member with 6 posts.
 
Join Date: Sep 2009
Experience: Advanced
06-Sep-2009, 05:32 AM #4
oh and switching the language to type really did fix the thing. Must have been that old HTML text book where I learned JavaScript.
MMJ's Avatar
MMJ MMJ is offline
Senior Member with 3,637 posts.
 
Join Date: Oct 2006
07-Sep-2009, 02:44 PM #5
That's the only problem with the randomizer.

A better way to build your array:

Code:
var myscript = [
	"Item1",
	"Item2",
	"Item3",
	"Item4",
	"Item5",
	"Item6",
	"Item7"
];
Reply

Tags
javascript

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.

Search Tech Support Guy

Find the solution to your
computer problem!




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



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
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 08:06 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.