Web Design and Development Forums

Display different images?

This is a discussion on "Display different images?" within the ASP Forum section. This forum, and the thread "Display different images? are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > ASP Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Jan 14th, 2008, 12:57   #1 (permalink)
Up'n'Coming Member
 
Join Date: Jan 2006
Location: Belfast
Posts: 57
Display different images?

Hi,
Within ASP, is it possible to display different images on a home page?

Ie, whenever you visit the homepage, you either view image 1 or 2 (randomly)?

Thanks in advance,

Ben
sing2trees is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jan 14th, 2008, 20:43   #2 (permalink)
Administrator
 
alexgeek's Avatar
 
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 4,102
Blog Entries: 9
Send a message via MSN to alexgeek
Re: Display different images?

Yes you can use the Rnd function then use an if/else statement to pick an image.
I will try and find an example later.
__________________
Languages: PHP, mySQL (queries), C#, (X)html, CSS, JS.


alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jan 14th, 2008, 21:26   #3 (permalink)
Section Manager - WOTM
Assistant Editor - LZ
 
Jack Franklin's Avatar
 
Join Date: May 2007
Location: Cornwall, England
Posts: 1,102
Blog Entries: 5
Re: Display different images?

Google is your friend

http://www.scriptdungeon.com/freeasp...reescripts1886
__________________
Section Manager (WOTM)

My Weblog & E-Portfolio
Catch me daily on: Twitter | Digg | Flickr
Jack Franklin is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jan 15th, 2008, 02:34   #4 (permalink)
Most Reputable Member
 
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,567
Blog Entries: 2
Send a message via Yahoo to Monie
Re: Display different images?

You could do it with custom made ASP Sub Function or the JavaScript Array function!

JavaScript Array Function:
Code: Select all
<head>
<script language="JavaScript">
<!-- Hide from old browsers

var imagenumber = 6 ;
var randomnumber = Math.random() ;
var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;
images = new Array
images[1] = "img/pic1.jpg"
images[2] = "img/pic2.jpg"
images[3] = "img/pic3.jpg"
images[4] = "img/pic4.jpg"
images[5] = "img/pic5.jpg"
images[6] = "img/pic6.jpg"
var image = images[rand1]
// -- End Hiding Here -->
</script>
</head>
..
..
<body>
<script language="JavaScript">
   // <-- Hide this script from old browsers --
   document.write('<IMG SRC="' + image + '">')
   // -- End Hiding Here -->
</script>
</body>

ASP Sub Function:
HTML: Select all
<%
Sub Random_pic()
Dim Pics
Randomize 
Pics=Int(Rnd()* 7)

Select Case Pics
Case "0"
    Response.write ("img/rdm1.gif")
Case "1"
    Response.write ("img/rdm2.gif")
Case "2"
    Response.write ("img/rdm3.gif")
Case "3"
    Response.write ("img/rdm4.gif")
Case "4"
    Response.write ("img/rdm8.gif")
Case "5"
    Response.write ("img/rdm6.gif")
Case "6"
    Response.write ("img/rdm7.gif")
End Select
End Sub
%>
'Call the sub function using the img tag!
<img src="<%Random_pic()%>">

Or, if you want less code, you can use this trick!


First Step:
Give your image a constant name like this:
  1. img/image_1.jpg
  2. img/image_2.jpg
  3. img/image_3.jpg
  4. img/image_4.jpg
  5. img/image_5.jpg
  6. img/image_6.jpg
  7. img/image_7.jpg
  8. img/image_8.jpg
Second Step:
Use the ASP Rnd Function inside your img tag like this:

<img src="img/header_<%=Int(Rnd()* 7)%>.jpg">

This code: <%=Int(Rnd()* 7)%> will generate a random number from 0-7
So the <img src="img/header_RandomNumberGeneratedHere"> will display the image according to the name!

Cool huh?
Cheers...
__________________

Monie is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jan 15th, 2008, 07:00   #5 (permalink)
Administrator
 
alexgeek's Avatar
 
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 4,102
Blog Entries: 9
Send a message via MSN to alexgeek
Re: Display different images?

Not an expert but I think you missed a parenthise on this line:
Code: Select all
var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;
should read this shouldn't it?
Code: Select all
var rand1 = Math.round( (imagenumber-1) * randomnumber)) + 1 ;
__________________
Languages: PHP, mySQL (queries), C#, (X)html, CSS, JS.


alexgeek is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jan 15th, 2008, 07:20   #6 (permalink)
Most Reputable Member
 
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,567
Blog Entries: 2
Send a message via Yahoo to Monie
Re: Display different images?

Nope, that code just works fine with me! What the code trying to tell us is...

Math.round((A-1) * B) + 1 ;

First the mathematics function will calculate the (A-1) and later multiply it with B, then plus the multiplication with 1.
Anyway, I got A for my Maths
__________________

Monie is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Jan 16th, 2008, 05:15   #7 (permalink)
Most Reputable Member
 
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,567
Blog Entries: 2
Send a message via Yahoo to Monie
Re: Display different images?

Sooo....
Anything new sing2trees? Do you happy with the solution or are you looking for something else?

Cheers...
__________________

Monie is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Just display the month? Jack Franklin PHP Forum 6 Feb 3rd, 2008 13:24
The Best way to display Images and text thewebkid Website Planning Discussion 7 Nov 19th, 2007 13:56
Status Bar Display Brakers New to Web Design 0 Jul 22nd, 2007 14:04
cannot display, help. Ascalon CSS Forum 3 May 18th, 2006 02:51
Use form to display non-preset images...? Mikemc JavaScript Forum 2 Feb 2nd, 2006 00:03



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 20:10.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59