Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > Classic ASP

Reply
 
LinkBack Thread Tools
Old January 14th, 2008, 08:57 AM   #1
WebForumz Member
 

Join Date: Jan 2006
Location: Belfast
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 sing2trees is on a distinguished road
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 January 14th, 2008, 04:43 PM   #2
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
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.
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
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 January 14th, 2008, 05:26 PM   #3
Most Reputable Member
 

Join Date: May 2007
Location: Cornwall, England
Posts: 1,421
Blog Entries: 8
Thanks: 18
Thanked 14 Times in 14 Posts
Rep Altering Power: 0 Jack Franklin will become famous soon enough
Re: Display different images?

Google is your friend

http://www.scriptdungeon.com/freeasp...reescripts1886
__________________
Yours is the Earth and everything that's in it
And - which is more - you'll be a Man my son!
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 January 14th, 2008, 10:34 PM   #4
Most Reputable Member
 

Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Rep Altering Power: 0 Monie is a jewel in the rough Monie is a jewel in the rough Monie is a jewel in the rough Monie is a jewel in the rough
Re: Display different images?

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

JavaScript Array Function:
Code:
<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 Code:
<%
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 January 15th, 2008, 03:00 AM   #5
Elite Veteran
 

Join Date: Jul 2007
Location: Webforumz 24/7
Age: 17
Posts: 3,799
Blog Entries: 9
Thanks: 2
Thanked 3 Times in 3 Posts
Rep Altering Power: 0 alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all alexgeek is a name known to all
Re: Display different images?

Not an expert but I think you missed a parenthise on this line:
Code:
var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;
should read this shouldn't it?
Code:
var rand1 = Math.round( (imagenumber-1) * randomnumber)) + 1 ;
__________________
Web Design and Development Blog

Alex Perry
Technical Administrator.
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 January 15th, 2008, 03:20 AM   #6
Most Reputable Member
 

Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Rep Altering Power: 0 Monie is a jewel in the rough Monie is a jewel in the rough Monie is a jewel in the rough Monie is a jewel in the rough
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 January 16th, 2008, 01:15 AM   #7
Most Reputable Member
 

Join Date: Feb 2004
Location: Borneo
Age: 28
Posts: 1,628
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Rep Altering Power: 0 Monie is a jewel in the rough Monie is a jewel in the rough Monie is a jewel in the rough Monie is a jewel in the rough
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

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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
Best way to display images/ Keeping file size down Oak Graphic Specifics 17 May 27th, 2008 01:03 PM
multiple rollover images change multiple images joshlindem HTML, XHTML and CSS 4 April 18th, 2008 05:11 AM
The Best way to display Images and text thewebkid How is this done? 7 November 19th, 2007 09:56 AM
cannot display, help. Ascalon HTML, XHTML and CSS 3 May 17th, 2006 10:51 PM
Use form to display non-preset images...? Mikemc JavaScript 2 February 1st, 2006 08:03 PM


Search Engine Optimization by vBSEO 3.2.0 RC8