www.webdeveloper.com
Results 1 to 6 of 6

Thread: need help with a project

  1. #1
    Join Date
    Mar 2012
    Posts
    6

    Cool need help with a project

    hey guys hows it going... new to the forums here... i'm currently working on a lil code for "Random Quotes" ok well i have it working very nice but still not what's desired, i'll explain...

    its here as a demo: http://abkclan.com/test/rotate.html

    currently its getting the random quote list from rotate.js in a list like this...

    Code:
    rotateQuotes.quotes = [
    "quote 1 here",
    "quote 2 here",
    "quote 3 here",
    "quote 4 here",
    "quote 5 here",
    "quote 6 here",
    ];
    well i could and have entered the data in like that... however i want to get the quote strings from a file 'http://anybodykillas.com/Quotes.txt'

    the data would look like this in the file:
    Code:
    quote 1 here
    quote 2 here
    quote 3 here
    quote 4 here
    quote 5 here
    quote 6 here
    what i need is to gather this data from Quotes.txt and put it in the format used in rotate.js

  2. #2
    Join Date
    Mar 2012
    Posts
    6
    my guess is i'll have to get all the strings by doing a split at each new line (\n) then they will be array'd so they are separated, then some how do a string replace. i suppose the first string: quotes[0] to be like this:
    "rotateQuotes.quotes = [ " quotes[0] ","

    the middle would be like this:
    "" quotes[1] ","

    and the last like this:
    "" quotes[1] "]&#59;"


    idk why im here :P RAGE! can't figure it out...

    want it from the Quotes.txt because our bot saves quotes from our mIRC chat rooms to that file.


    couple of people say i just have to do my random quotes differently where it splits the string and randoms the array id number.

    others say i need jquery for what i wanna do but i wouldnt see y considering its just javascript anyways

  3. #3
    Join Date
    Feb 2012
    Posts
    218
    use PHP to get quotes from file.
    PHP Code:
    $quotes file('Quotes.txt'FILE_IGNORE_NEW_LINES FILE_SKIP_EMPTY_LINES); 
    and here is the javascript
    Code:
    rotateQuotes.quotes = ["<?php echo implode('","', $quotes)?>"];

  4. #4
    Join Date
    May 2005
    Location
    Dirty Jersey
    Posts
    1,403
    PHP isn't necessary to do what you're asking. you can keep everything native an just use AJAX to request the contents of the text file. here's an example of doing just that:

    http://www.w3schools.com/ajax/tryit....=tryajax_first

    in your case, you wouldn't just be placing the entire contexts of the text file into your page using "innerHTML". you'd have to be a bit (a lot) more precise. so, what you'd do is take the responseText and place each quote within the responseText into an instance in some array. that could be done using the "split" function against the responseText string, splitting at any instance of
    Code:
    \n
    so if your text file said:

    Code:
    quote 1 here
    quote 2 here
    quote 3 here
    quote 4 here
    quote 5 here
    quote 6 here
    and you split it based on "\n", you'd get an array that looked like:

    Code:
    [0] = "quote 1 here"
    [1] = "quote 2 here"
    [2] = "quote 3 here"
    ...
    then, using more javascript, you randomize the quote and insert it into the DOM. EASY!!!
    Last edited by Angry Black Man; 03-03-2012 at 11:37 AM.

    1. If you reply to my post, and your reply would then appear directly beneath my post, DON'T QUOTE MY ENTIRE POST!!! IT'S REDUNTANT!!! IT'S ASININE!!!! IT'S REDUNDANTLY ASININE!!!!! DON'T DO IT!!!!
    2. jQuery extends the functionality of JavaScript. If you don't know JavaScript, give up on that jQuery script and learn JavaScript. You'll save yourself a lot of frustration, I promise.
    3. Use the [code][/code] tags. Otherwise, you may be left wondering why no one responded to your eyesore of a thread.


  5. #5
    Join Date
    Mar 2012
    Posts
    6
    thx the PHP method will work great i do believe...
    at first was tring to avoid PHP scripts because there not allowed on the site being used... however i just made this on my own host and added it to the theme in the location desired with an iframe, my host allows php so i dont have to avoid using it anymore... lol didnt think about it, was stuck on making it work with js, and everything i tried failed :P

  6. #6
    Join Date
    Mar 2012
    Posts
    6
    ok yea the PHP method failed for some reason not sure why.... maybe i did it wrong idk...

    well think he desided just to update the file with the list, with the bot instead of making a Quotes.txt file... think ima try the AJAX method later. idk nothing in AJAX lol only what it is and what its made to do... do believe i need to learn

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles