Random Quotes Problem -

They have: 8 posts

Joined: Mar 1999

I have had a random one-liner JavaScript on my website for a while now. However, recently I tried to put it in a .js file, but IE5 doesn't like .js's, so I put the script back into the html file. However, I started getting error messages upon doing this. do one responded at comp.lang.javascript, so I am asking, no, *begging* you all kind, kind souls to help.

here is the code: (I cut out part of it because it's so long)

<script language="JavaScript">
<!-- Begin
var howMany = 348
var quote = new Array(howMany+1)
quote[0]="You! Off my planet!"
quote[1]="It's important to watch what you eat. Otherwise, how are you going to get it into your mouth? (Matt Diamond)"
quote[2]="'They couldn't hit an elephant at this dist---' —General John B. Sedgwick's last words, 1864"
quote[3]="If Beethoven had been killed in a plane crash at the age of 22, it would have changed the history of music, and of aviation. - Tom Stoppard"
quote[4]="I'm not weird, I'm gifted!"
quote[5]="I do not suffer from insanity. I enjoy every minute of it!"
quote[6]="Behold the power of cheese!"
quote[7]="'I will engage in a battle of wits with one who is unarmed.' - Winston Churchill"
quote[8]="Good, bad...I'm the guy with the gun! -Ash, Army of Darkness"
quote[9]="Enjoy your feeble lives!"
quote[10]="Keeping the insanity coming."
quote[11]="Oh yes, mwa ha ha ha. You're so silly."
quote[12]="I am proud to announce that work has begun in earnest on my 1,234,451,999,835th project which should be nearing completion by the middle of the next millennium. Keep your eyes peeled. I'm on fire!"
quote[13]="Doomsday's a commin' lads. This round 'o drinks is on me."
quote[14]="As the wild carrot shaman once said to me, 'Be afraid. Be very afraid. Unless you're not afriad, in which case I want you to very solemnly swear to me that you will be something else.' Of course he could have been referring to attacking pretzel strongholds, butttt...I could be wrong."
quote[15]=" - 'I stab at thee!' <br> - 'You know if you stopped narrating I wouldn't be able to anticipate you so well.' <br> - 'Frivilous dog! Slash!'"
quote[16]="King Kong died for our sins."
quote[17]="You don't win a war by dying for your country. You win by making the other poor [guy] die for his.' - General Patton"
quote[18]="Anyone got a grenade pin handy?"
quote[19]="Keep cycling Jimmy! The drill's no good if you're going too slow!"
quote[20]="Then there's that odd smoke coming from my third dresser drawer. Smells good..."
quote[21]="Of course the pen is mightier than the sword, but only because you can get it though medal detectors."
quote[22]="'-So you think *I'm* the murderer? What do I have to do to convince you that I'm not, be the next victim?' <br> -'Well, that would be a start.'"
quote[23]="A messy room is a happy room. My room is delirious."
quote[24]="Every once in awhile I get the urge to use my evil genius to crush and enslave the globe without mercy, but then I realize I'd probably just hurt my back, so I grab a [coke] and go back to the couch instead. (David James)"
quote[25]="Oral promises aren't worth the paper they're written on. - Samuel Goldwyn"

(snip)

quote[351]="What comes first, new schools or portable classrooms?"
quote[352]="If you're not confused, you're not informed."
quote[353]="I always try to count my blessing, but I am no good at fractions."
quote[354]="If you can't laugh at yourself, you may be missing the colossal joke of the century. -- Dame Edna"
var randscript = -1
while (randscript < 0 | | randscript > howMany | | isNaN(randscript)){
randscript = parseInt(Math.random()*(howMany+1))
}
return randscript
}
quo = rndnumber()
quox = quote[quo]
document.write(quox)
// End -->
</script>

there was nothing wrong with the part I cut out, don't worry.
Also, how would I split this up, so that part of it is in the head of the html file?

------------------
~~~~~~~~~~~~~~~~~~~~~~
The Infinitation speaks.
"A-B-C-D-E-Q-R-T-H-J-A-K-L-P-O-I-U-G-Y-Y-Y-Y-Y...dang, not again."
The Crossroads of Infinity - http://www.animorphs.nu
~~~~~~~~
Madness takes its toll. Please have exact change.
I'm not schizophrenic, I just have people living inside my head.
EARTH FIRST! We'll strip mine the other planets later
Join the army, meet interesting people, kill them.
Leggo my ego!
I intend to live forever or die trying -Spider Robinson
Error accessing file. Format hard drive now? (Y/Y)
Runtime Error 6D at 417A:32CF: Incompetent User.
ALERT: Enter any 11-digit prime number to continue.
Hard work pays off in the future. Laziness pays off now.
I.R.S. - We've got what it takes to take what you've got.
For Sale: Parachute. Only used once, never opened, small stain.
Anyone got a grenade pin handy?
Keeping the insanity coming.
ICQ: 7781485 E-mail: [email protected]

They have: 2,390 posts

Joined: Nov 1998

Just a note to say that I have contacted Jeffrey (who is our resident expert) as is very busy and may not come accross this post. So please be patient if no one else gets to this today.
Also, I use a .js file om my new site:
http://www.what-next.com/new
which seems to work fine in N4, IE4 and IE5.
I had no idea IE5 didn't like them!
JP

------------------
The Webmaster Promotion and Resource Site
www.what-next.com
The NEXT step in Designing and Promoting your Website

They have: 8 posts

Joined: Mar 1999

Oh, and I realize that the howMany var is off. I fixed that and it still doesn't work.

------------------
~~~~~~~~~~~~~~~~~~~~~~
The Infinitation speaks.
"A-B-C-D-E-Q-R-T-H-J-A-K-L-P-O-I-U-G-Y-Y-Y-Y-Y...dang, not again."
The Crossroads of Infinity - http://www.animorphs.nu
~~~~~~~~
Madness takes its toll. Please have exact change.
I'm not schizophrenic, I just have people living inside my head.
EARTH FIRST! We'll strip mine the other planets later
Join the army, meet interesting people, kill them.
Leggo my ego!
I intend to live forever or die trying -Spider Robinson
Error accessing file. Format hard drive now? (Y/Y)
Runtime Error 6D at 417A:32CF: Incompetent User.
ALERT: Enter any 11-digit prime number to continue.
Hard work pays off in the future. Laziness pays off now.
I.R.S. - We've got what it takes to take what you've got.
For Sale: Parachute. Only used once, never opened, small stain.
Anyone got a grenade pin handy?
Keeping the insanity coming.
ICQ: 7781485 E-mail: [email protected]

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

I got it to work for the first six by making a few changes. You should be able to use the 350 or so quotes you have by adding back in the additional quotes and changing the how many variable back.

When I first ran it, I got a syntax error on the line with the "or" statements. The two lines that represent "or" need to be together, with no space in between:

while (randscript < 0

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

Infinity,

You're welcome, let me know how it turns out? Hey? How did you know I was beautiful anyway? Umm.. just kidding.

JP,

Thanks for the compliment,
glad I could help out.

------------------
John Pollock
http://www.pageresource.com

They have: 2,390 posts

Joined: Nov 1998

Infinity,I had a look for this script on your site but could not find it. URL?
Thanks.

PS We have a new JavaScript expert! Thanks John.

JP

------------------
The Webmaster Promotion and Resource Site
www.what-next.com
The NEXT step in Designing and Promoting your Website

They have: 8 posts

Joined: Mar 1999

John: Thanks alot! I'm applying the changes right now! You're beautiful, man, keep it up!
JP: I removed the script from my site because of all the error messages it was causing. I saved it in a text file, and that's where I'm editing it.

Thanks a lot, both of you!

------------------
~~~~~~~~~~~~~~~~~~~~~~
The Infinitation speaks.
"A-B-C-D-E-Q-R-T-H-J-A-K-L-P-O-I-U-G-Y-Y-Y-Y-Y...dang, not again."
The Crossroads of Infinity - http://www.animorphs.nu
~~~~~~~~
Madness takes its toll. Please have exact change.
I'm not schizophrenic, I just have people living inside my head.
EARTH FIRST! We'll strip mine the other planets later
Join the army, meet interesting people, kill them.
Leggo my ego!
I intend to live forever or die trying -Spider Robinson
Error accessing file. Format hard drive now? (Y/Y)
Runtime Error 6D at 417A:32CF: Incompetent User.
ALERT: Enter any 11-digit prime number to continue.
Hard work pays off in the future. Laziness pays off now.
I.R.S. - We've got what it takes to take what you've got.
For Sale: Parachute. Only used once, never opened, small stain.
Anyone got a grenade pin handy?
Keeping the insanity coming.
ICQ: 7781485 E-mail: [email protected]

They have: 2,390 posts

Joined: Nov 1998

John,
Can I call you beautiful too?
Are we getting off topic here?
Actually, on a more serious note - maybe I should set up a geberal forum, not related to any thing in particular. Any comments?
Cheers,
JP

------------------
The Webmaster Promotion and Resource Site
www.what-next.com
The NEXT step in Designing and Promoting your Website

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

JP,

The general forum sounds like a good idea.

Perhaps it would be a good place for everyone to tell me how beautiful I am.. or maybe not

------------------
John Pollock
http://www.pageresource.com

They have: 62 posts

Joined: Dec 1998

I'm a little late to this party, but hope this helps...

This is the basic script I use on eons.com to rotate my tips and tricks:

<SCRIPT>
<!--

// Set to number of random items
var number=5;

// Becomes generated random number
var random_number=0;

// Random number generating
today=new Date();
jran=today.getTime();
ia=9301;
ic=49297;
im=233280;
jran = (jran*ia+ic) % im;
random_number=Math.ceil( (jran/(im*1.0)) *number);

// Create and define arrays.
title = new Array(5);
content = new Array(5);
link = new Array(5);

title[0] = "Title One";
content[0] = "Sample paragraph one... ";
link[0] = "filename1.htm";

title[1] = "Title Two";
content[1] = "Sample paragraph two... ";
link[1] = "filename2.htm";

title[2] = "Title Three";
content[2] = "Sample paragraph three... ";
link[2] = "filename3.htm";

title[3] = "Title Four";
content[3] = "Sample paragraph four... ";
link[3] = "filename4.htm";

title[4] = "Title Five";
content[4] = "Sample paragraph five... ";
link[4] = "filename5.htm";

// -->
</SCRIPT>

- - - BODY - - -

<SCRIPT>
<!--
document.write("<H2><A HREF='" + link[random_number-1] + "'>" + title[random_number-1] + " </A></H2> <BR> " + content[random_number-1]);
// -->
</SCRIPT>

------------------
Jeffrey Ellison
[email protected]
http://www.eons.com - Free Online Tools for Webmasters

They have: 62 posts

Joined: Dec 1998

Example of above script:

http://www.eons.com/example1.htm

[This message has been edited by Jeffrey Ellison (edited April 12, 1999).]

They have: 8 posts

Joined: Mar 1999

Thanks, Jeff, but the script I have working now works just fine for me. BTW, John, you mentioned that .js files work fine in IE5 for you. Well, I'm a JavaScript newbie, and I'm not entirely certain I made 'em correctly. What exactly do I need to do to make a .js file (link and what's in the .js file)? I do the following (w/square brackets instead of angle ones):

[script language="JavaScript" src="filename.js"] [/script]

and in the js file:
[script language="JavaScript"]
<!--Hide
script goes here
-->
[/script]

Is this correct? Thanks in advance.

They have: 8 posts

Joined: Mar 1999

oh sorry, that was JP who said that. Forgive me.

They have: 2,390 posts

Joined: Nov 1998

First of all, welcome back Jeff, I hope you get time off in your workload to visit the forums more regularly.

Infinity, I use the following code to link to the .js file.

quote:<script src="staticlogo.js">
© Dynamic Drive (www.dynamicdrive.com)
</script>

The dynamic file bit is where I got the file from BTW.
JP

------------------
The Webmaster Promotion and Resource Site
www.what-next.com
The NEXT step in Designing and Promoting your Website

They have: 8 posts

Joined: Mar 1999

Well, JP, I tried to do that, but it didn't work. I just got a blank page. Was the format that I .js file in (see above post) correct?
Oh, and John, I visited pageresource.com. I'm currently learning CSS. Great site!
(Don't worry Jeff, I'll go to your site too )

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

Infinity,

Thanks for the compliment on my site, I hope you are enjoying the CSS section.

As for the external js file, the coding for the head section looked OK from you and JP. It would be something like this:

<SCRIPT language="JavaScript" SRC="http://someplace.com/jxt1.js"></SCRIPT>

I think the problem may be that you have added an extra set of <SCRIPT></SCRIPT> tags inside the .js file itself.

In the external file, just put in your code and your functions, that is all it should need.

Leave out the opening and closing comments as well. They are used when the script is embedded in the page to keep old browsers from displaying the code. The old browsers won't understand the SRC="" command, so they shouldn't show it.
(Though NS 3 can do some strange things, especially with the document.write command, be sure to test if you have viewers with NS 3).

------------------
John Pollock
http://www.pageresource.com

They have: 2,390 posts

Joined: Nov 1998

Sorry Infinity, I didn't see you wanted help on the ACTUAL .js file, that is why I only helped with the link itself Shocked .
JP
PS John you're beautiful, and I bet you're blushing!

------------------
The Webmaster Promotion and Resource Site
www.what-next.com
The NEXT step in Designing and Promoting your Website

They have: 8 posts

Joined: Mar 1999

Oh dear.....

I still can't get the js files to work. I made the [script] tags the same way as you showed, the js file itself was the same as the script on my page (minus the script tags and the comment thingys), and it didn't work. I realized that I'm not exactly being clear, but I'm currently in a bad mood because I've had it up to *_here_* with this computer. I've tried every concievable fix and the #&$%@&$^#&@$%#&!*!&@#% thing still won't #&$%@&$^#&@$%#&!*!&@#% work. Any idea what could be wrong? Anything I have to add or take out? Please?!

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

JP,

If I get any more beautiful, I'm going to have a constant blush! I'm going to have to hit myself with an ugly stick or something

Infinity,

How are you calling the javascript function in your document? The SCRIPT tag only lets the browser know where to go to get the contents of a function or variable. You haven't mentioned calling the function in the body of the document.

I had forgotten that the script was written to be included in the document body. Rewrite your .js file like this (with the number and quote changes you need):

---------------------------------------
var howMany = 5;
var quote = new Array(howMany+1);

quote[0]="You! Off my planet!";
quote[1]="It's important to watch what you eat. Otherwise, how are you going to get it into your mouth? (Matt Diamond)";
quote[2]="'They couldn't hit an elephant at this dist---' —General John B. Sedgwick's last words, 1864";
quote[3]="If Beethoven had been killed in a plane crash at the age of 22, it would have changed the history of music, and of aviation. - Tom Stoppard";
quote[4]="I'm not weird, I'm gifted!";
quote[5]="I do not suffer from insanity. I enjoy every minute of it!";

function rndnumber()
{
var randscript = -1;
while (randscript < 0

They have: 8 posts

Joined: Mar 1999

Okay. It still doesn't work. I tried every possible configuration of the script tags and js file and all that, and I'm just calling it quits on the whole js file idea. It wasn't really necessary for my site, I only wanted to reduce the clutter on my main site. If you wanna look at what I have, go to: www.geocities.com/~thoth50/test3.html

That's all, folks. Sorry to make you do all this for a poor unenlightened JavaScript newbie such as myself

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.