Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2003
    Location
    southwest
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling random text from external file

    I am looking for a quick way to update libraries of quotes, either randomly generated or or viewed based on subject, author, text, etc. The key thing I would like to do is have either a text file w/delimiters (if needed), or a js file that holds content. The script would call from the external file. The obvious reason for this is that once one has say hundreds of quotes, it gets messy dealing with arrays, etc. At this point I thought js would be good cause it can be totally client side. The external file of quotes can be added, updated, edited quickly and from anywhere, including my PDA with a text editor. Unless I am missing something in my search through this forum and at other scripting sites, there does not appear to be anything like this. Would love some very specific help as I can do enough coding to tweak scripts but am not a coder by nature.

    thanks...

  • #2
    New Coder
    Join Date
    Mar 2003
    Location
    Tampa, FL
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    JavaScript running on a client PC cannot open external files for security purposes.

    The best thing to use would be Perl or PHP...but if you need to use Javascript you can do this:

    1. Create a file called quotes.js and enter the quotes like this:
    Code:
    var quote = new Array(20)
    quote[0] = "Buy a Pentium 586/90 so you can reboot faster."
    quote[1] = "2 + 2 = 5 for extremely large values of 2."
    2. Put this code in your HTML file:
    Code:
    <script src="quotes.js"></script>
    <script>
    document.write(quote(Math.round(Math.random()*(quote.length-1))+1));
    </script>
    Well...that's the general idea...I'm sure you get the picture...anything more complicated than this and I'd recommend using PHP or Perl.

    Lewis

  • #3
    New to the CF scene
    Join Date
    Mar 2003
    Location
    southwest
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Tardy thanks

    Lewis:
    I apologize for the tardy response. Got pulled away and it got late. Thanks for the assist here. At this point I think this is the idea I have to go with unless I move to some other scripting language. I coud do Perl or PHP but really like the idea of being able to have my stuff be portable if at all possible. But I guess I'll crank up my server and play around as well.

    Thanks,
    Sam

  • #4
    New Coder
    Join Date
    Mar 2003
    Location
    Tampa, FL
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Alrighty then...let me know how it goes!

    Lewis


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •