Want you banner here?


Matrix28 > ASP > Random Items (Text only)

Quick quotes | Write review | Report error | Discuss/get help on this script in our forums
QuickQuotes is a quick and easy to use quote management database. Use it to display famous quotations, or your own, anywhere on your web site. And it is free!

ASP - unique random numbers | Write review | Report error | Discuss/get help on this script in our forums
There are many things you can do to randomize content in your .asp document, however if you use one element repeatedly you run the risk of generating the same random value/content within a page. To avoid that you can make sure you random items (in this case numbers) are unique. The following example will generate five random numbers between one through five. After each random number is selected it is compared to the previous selections and if it was previously selected a new number is chosen. This is great for randomizing the order of content on a page.

ASP - unique random leters | Write review | Report error | Discuss/get help on this script in our forums
Some computers systems require that each letter in a password be unique. If you want to give that kind of look or would just prefer that all initial passwords that you issue new users to your site be unique then this is the script for you. A simple for next loop randomly chooses a number between 26 and 97 converts that to a letter and stores it in an array. A second for next loop compares the current selection to previous ones made and if it is not unique reselects until it finds a unique character. Refresh the output of this example a couple of times for a complete demonstration as each potential selection is written to the browser as well as the unique variable created.

Random Db observation | Write review | Report error | Discuss/get help on this script in our forums
Most random content scripts involve the loading of arrays to call the one that you want to output. As the number of items you want to display randomly increases so may your need to serve them from a database rather than from large amounts of manually updated text files. The following code will select a random quote from the opening of the Simpson’s as well as display the observation number and the total number of observations found from the query.

Reading random text | Write review | Report error | Discuss/get help on this script in our forums
Reading text from an outside source is easily accomplished with an include statement similar to this . If you wanted to dynamically include text you would like to be able to do something similar to this . The only problem is since include statements are resolved before just about anything else you'll get an error trying to dynamically write the name of the file you're attempting to include. You can write a select case statement or an if then statement to resolve this, but understanding that the server will be resolving many includes to display the contents of one is kind of wasteful. Providing that you're only passing code for the client to interpret (HTML, JavaScript, etc) you can dynamically include text into your asp document. The following example will randomly select a number between one and five, read the contents of a .htm file and write it out to the browser. The file that is being included does not have to be .htm just text based. The .htm extension was chosen on the off chance anyone may hit the page directly, so it would display rather than download. Refresh the output page for a more complete demonstration

Random colors | Write review | Report error | Discuss/get help on this script in our forums
Add a little bit of variety to the look of your website by randomly changing the colors of the page background, table cell backgrounds and/or hyperlinks. A random variable, a select case statement and response.write placed inside any color command enables you to show any range of colors you want.

ASP eight ball | Write review | Report error | Discuss/get help on this script in our forums
A website dedicated to web programming would not be complete without it's own version of the Magic 8 Ball. At least that's our feeling. Actually, this humble 8 ball script demonstrates three things. A random number, a dim statement and a tautology that uses a form variable to determine if it's the users first time asking a question.

ASP random hyperlinked images | Write review | Report error | Discuss/get help on this script in our forums
Hyperlinking random images is an quick and easy way to make a page look unique from others in the same template and enables you to highlight specific places within your website (or others) you want to drive traffic to. The following example contains links to seven of the most popular search engines and their logos. Each time the page is refreshed the script will select a random number from one to seven and dynamically write the appropriate image and hyperlink to the browser.
Page 1 | Page 2