Results 1 to 10 of 10

Thread: getting one liners randomly chosen from a set

  1. #1

    Thread Starter
    Fanatic Member mikeycorn's Avatar
    Join Date
    Jun 2000
    Location
    Aliso Viejo, CA, USA
    Posts
    526

    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?
    ~ mikeycorn

    With over 45,000 Questions in the User Submitted Database, it's the Most Popular Quiz Creation Software on the Net:

    PEST - The Personal Exam Self-Tester

  2. #2
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    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.

  3. #3

    Thread Starter
    Fanatic Member mikeycorn's Avatar
    Join Date
    Jun 2000
    Location
    Aliso Viejo, CA, USA
    Posts
    526
    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.)
    ~ mikeycorn

    With over 45,000 Questions in the User Submitted Database, it's the Most Popular Quiz Creation Software on the Net:

    PEST - The Personal Exam Self-Tester

  4. #4

    Thread Starter
    Fanatic Member mikeycorn's Avatar
    Join Date
    Jun 2000
    Location
    Aliso Viejo, CA, USA
    Posts
    526
    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.
    ~ mikeycorn

    With over 45,000 Questions in the User Submitted Database, it's the Most Popular Quiz Creation Software on the Net:

    PEST - The Personal Exam Self-Tester

  5. #5
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    You can either escape it with \ like so:

    Code:
    document.write('single quote \\'');
    or use double quotes:

    Code:
    document.write("single quote '");

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    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.

  7. #7

    Thread Starter
    Fanatic Member mikeycorn's Avatar
    Join Date
    Jun 2000
    Location
    Aliso Viejo, CA, USA
    Posts
    526
    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.)
    ~ mikeycorn

    With over 45,000 Questions in the User Submitted Database, it's the Most Popular Quiz Creation Software on the Net:

    PEST - The Personal Exam Self-Tester

  8. #8
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    You think you have enough catch-phrases in there, there must be about 50

  9. #9

    Thread Starter
    Fanatic Member mikeycorn's Avatar
    Join Date
    Jun 2000
    Location
    Aliso Viejo, CA, USA
    Posts
    526
    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."

    ~ mikeycorn

    With over 45,000 Questions in the User Submitted Database, it's the Most Popular Quiz Creation Software on the Net:

    PEST - The Personal Exam Self-Tester

  10. #10
    Frenzied Member Rick Bull's Avatar
    Join Date
    Apr 2002
    Location
    England
    Posts
    1,444
    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
  •  



Click Here to Expand Forum to Full Width