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...
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] "];"
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
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:
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:
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.
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
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
Bookmarks