|
-
Oct 24th, 2002, 03:39 AM
#1
Thread Starter
Fanatic Member
getting one liners randomly chosen from a set
Real newbie web design question:
I'm working with dreamweaver 4 and I can't figure where to look in the help to find out how you set it up to where I have a group of different one-liners (a set of single lines of text) and have a different one randomly selected and displayed each time the page is hit.
Anyone?
-
Oct 24th, 2002, 05:34 AM
#2
Frenzied Member
This is one way to do it using JavaScript:
Code:
<script type="text/javascript"><!--
function randomNumber(maxValue, minValue) {
//If minValue/maxValue is missing make it/them 0/1
if (minValue == null) minValue = 0;
if (maxValue == null) maxValue = 1;
//Return the number
return (Math.round(maxValue * Math.random()) + minValue);
}
//List of all lines wanted - add your own
var oneLiner = new Array(
'Line 1',
'Line 2',
'Line 3',
'Line 4'
);
//Output the line
document.write(oneLiner[randomNumber(oneLiner.length-1)]);
document.close();
//--></script>
Just add the lines you want to be written to the array, seperated by commas, and encased in single or double quotes.
-
Oct 24th, 2002, 10:36 AM
#3
Thread Starter
Fanatic Member
Wow! That is cool. Thanks Rick Bull. (Damn, I'm afraid that little snippet right there has me thinking it's time to move beyond the comfy confines of VB and start learning some new tricks.)
-
Oct 24th, 2002, 11:11 AM
#4
Thread Starter
Fanatic Member
How do I get single quotes inside the single quotes???
I figured maybe the percent sign and the ascii code.
As an example, I tried 'It%39s only me.' but it didn't work.
-
Oct 24th, 2002, 05:01 PM
#5
Frenzied Member
You can either escape it with \ like so:
Code:
document.write('single quote \\'');
or use double quotes:
Code:
document.write("single quote '");
-
Oct 24th, 2002, 05:08 PM
#6
In JavaScript ' and " are completly interchangeable, except that the starting and ending sign of one particular string must be the same (you can't do "this is a string')
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 24th, 2002, 06:17 PM
#7
Thread Starter
Fanatic Member
Awesome, thanks guys.
If you want to check out the little spice you just helped me add to my web page, check out the slogans at the bottom of the page:
www.vellosoft.com
And be sure to hit refresh a bunch of times (some of them are funnier than others.)
-
Oct 25th, 2002, 07:11 AM
#8
Frenzied Member
You think you have enough catch-phrases in there, there must be about 50
-
Oct 25th, 2002, 12:00 PM
#9
Thread Starter
Fanatic Member
Actually, that nice JavaScript you provided is dipping into an array of 367 slogans I had put together for a quiz on corporate slogans. My favorite are the one's that make absolutely no sense, like "Vellosoft. The Other White Meat." or "Vellosoft. Just for the Taste of It."
-
Oct 25th, 2002, 12:18 PM
#10
Frenzied Member
Ah right, it all makes sense now.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|