1. Find a quote list (example: quotes).
2. In the quote list, how is each quote separated? comma? crlf? br tag?
3. Use $.get to get the content of the quote list (line 1).
4. Within the function, split the data into an array on the quote separation characters to create an array of quotes (line 2).
5. Return a random number within the length of the array and display the random quote (lines 3 and 4).
Example:
1. $.get('../pic/quotes.html', function(data) {
2. var quotes = data.split("<BR><BR>");
3. var idx = Math.floor(quotes.length * Math.random());
4. alert(quotes[idx]);
5. );
For the random amounts to add up, I use the following:
1. function randomArrayResult()
2. {
3. var arr = $("#arrayvalues").val().split(",");
4. var total = 0;
5. $.each(arr,function()
6. {
7. total += parseInt(this);
8. });
9. $("#randomArrayResult").val(total);
10. }
Line 3 splits the comma-delimited string into an array of numeric values. Line 5 creates a loop to examine each numeric item in the array of numeric values. Line 7 converts the current item in the array "this" into a number and adds the number to the current value of the variable "total". Line 9 displays the result by setting the label "randomArrayResult" to the result.