Go Back   DevHunters.com l Webmaster Forum - Web Advertising - Web Design - SEO Forums > Webmaster / Coding / Web Design Discussion > JavaScript Programming

JavaScript Programming Discuss javascript coding.

Have A Look At Some Of Our Webmaster Related Sponsors!


Script Directory


Advertise Here


Market Leverage


Free Templates

3D Guide-Characters
3D Guide-characters


Advertise Here

Reply
 
LinkBack Thread Tools Display Modes
Old 03-27-2007, 04:53 AM   #1 (permalink)
Junior Member
 

Join Date: Mar 2007
Posts: 4
iTrader: 0 / 0%
Hunter Bux: 10.00
montsa007 is on a distinguished road
Thumbs up Random quote generator script,random quotes in ur site (javascript)

a very simple javascript to generate random quotes at any place of a webpage you want it to appear and any quote which you want to appear. Just insert this script in your webpage wherever you want the random quote to appear.
remember change quotes with yours
Code:
<script language="JavaScript">
var Quotation=new Array() 
Quotation[0] = "Time is of the essence! Comb your 
hair.";
Quotation[1] = "Sanity is a golden apple with no 
shoelaces.";
Quotation[2] = "The image is more than an idea. It 
is a vortex or cluster of fused ideas and is endowed 
with energy. ~ Ezra Pound";
Quotation[3] = "Honesty blurts where deception 
sneezes.";
Quotation[4] = "Pastry satisfies where art is 
unavailable.";
Quotation[5] = "Image creates desire. You will 
what you imagine. ~ J. G. Gallimore";
Quotation[6] = "The image cannot be dispossessed 
of a primordial freshness, which idea can never 
claim. An idea is derivative and tamed. The image 
is in the natural or wild state, and it has to be 
discovered there, not put there, obeying its own 
law and none of ours. ~John Crowe Ransom";
Quotation[7] = "Wishes are like goldfish with 
propellors.";
Quotation[8] = "Love the river's \"beauty\", but live 
on a hill.";
Quotation[9] = "Invention is the mother of too 
many useless toys.";
Quotation[10] = "I want to know God's thoughts... 
the rest are details.~ Albert Einstein ";
// 
======================================
// Do not change anything below this line
// 
======================================
var Q = Quotation.length;
var whichQuotation=Math.round(Math.random()*
(Q-1));
function showQuotation(){document.write(Quotation
[whichQuotation]);}
showQuotation();
</script></p>
quotes can be increased but should be only 1 liners!
montsa007 is offline   Reply With Quote
Old 06-14-2007, 04:03 PM   #2 (permalink)
Administrator
 
J0ker's Avatar
 

Join Date: Apr 2007
Posts: 165
iTrader: 0 / 0%
Hunter Bux: 1,520.00
J0ker is on a distinguished road
Send a message via MSN to J0ker
Default

Very simple, yet cool javascript code. In case any one is interested I will breifly explain what is happining in the code. I gave you reputation for this useful code to the community!

1. First it makes a variable called "Quotation" and make it an array (an array is basically a variable that holds several variables.

2. Now it sets the different variables inside the array. Quotation[1] is the first variable inside the Quotation array, so you just increase the number to add another variable (which we are setting to contain quotes), so you could have 50 quotes if you wanted to!

Now the part that is a bit more complicated:

Quote:
var Q = Quotation.length;
3. This makes a new variable "Q" to be the number of variables in the array, in this case it would be 10.

Quote:
var whichQuotation=Math.round(Math.random()*
(Q-1));
4. This makes a new variable "whichQuotation". It uses the random command that is a part of the math functaions to, in simple words, randomly pick which variable, or quote, in the array to choose.

Quote:
function showQuotation(){document.write(Quotation
[whichQuotation]);}
showQuotation();
This makes a function "showQuotation". A function is basically a new command that once executed completes the commands inside of it, it is very helpful when doing the same operation multiple times. The function uses document.write to display the variable Quotation[whichQuotation]. Now whichQuotation is a variable that was set as a random number of one of the variable inside the array's numbers, therefore it actually shows on of the quotes (i.e. Quotation[3] could be the randomly picked on, so whichQuotation contains the number 3, so the 3 is put in its place and the variable is now Quotation[3], which is the third variable in the Quotation array. So the script would show the text "Honesty blurts where deception
sneezes.".)

If this was confusing to you, don't worry. Just copy and paste that to the spot in your website you want a random quote, then change the quotes to ones you want, or even things that aren't quotes, and it will work fine. You can change the number of quoates as well, by just adding in a new variables that goes up one, so if you wanted 1 extra quote the ones already there you would just add this after the end of the 10th quote:

Quotation[11] = "Your quote here";
J0ker is offline   Reply With Quote
Old 11-05-2007, 11:07 PM   #3 (permalink)
Member
 

Join Date: Nov 2007
Posts: 33
iTrader: 0 / 0%
Hunter Bux: 0
ukiya006 is on a distinguished road
Default

wow wow wow~ O.O
these scripts are real cool. i'm gonna test them out in my web pages. :D
ukiya006 is offline   Reply With Quote
Old 11-05-2007, 11:12 PM   #4 (permalink)
Field Master
 

Join Date: Oct 2007
Posts: 282
iTrader: 1 / 100%
Hunter Bux: 260.00
mountlaurel is on a distinguished road
Default

yes... this one is simple and cool, i'm looking for these scripts for a week thanks...
mountlaurel is offline   Reply With Quote
Old 01-03-2008, 04:37 PM   #5 (permalink)
Senior Moderator
 
SpOrTsDuDe.Reese's Avatar
Default

Or you could just use the Math.Random object. Thats just what I use. That example seemed overly complicated.
SpOrTsDuDe.Reese is offline   Reply With Quote
Old 02-08-2008, 05:54 PM   #6 (permalink)
New Hunter
 

Join Date: Dec 2007
Location: United Kingdom - Dorset - Bournemouth
Posts: 88
iTrader: 0 / 0%
Hunter Bux: 5.00
Smiggy will become famous soon enoughSmiggy will become famous soon enough
Send a message via MSN to Smiggy
Default

My Attempt:

Code:
function Random_Note()
{
	var note = new Array(6)
	var Select = Random();
	note[0] = "Quote";
	note[1] = "Quote";
	note[2] = "Quote";
	note[3] = "Quote";
	note[4] = "Quote";
	note[5] = "Quote";
	document.getElementById('Random').innerHTML = "<b>" + note[Select] + "</b>";
	var Time = setTimeout("Random_Note()", 1500);
}
function Random()
{
    var Random_Number_Selection = Math.floor(Math.random()*6);
    return Random_Number_Selection;
}
__________________
<!-- I can type the entire Alphabet in 2.19 seconds -->

/* (X/D)Html, Css, Javascript, Ajax, Xml (DTD), PHP, MySQL, E4X */
/* Learning C++ and German */
Smiggy is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -5. The time now is 07:34 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios