Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-19-2009, 04:01 AM   PM User | #1
tonynoname123
New Coder

 
Join Date: Nov 2009
Location: www.nn11.darkbb.com
Posts: 40
Thanks: 2
Thanked 0 Times in 0 Posts
tonynoname123 is an unknown quantity at this point
Question Random image script

Does anyone have a script, that can display a random image of the images I select?I'm going to use it for a type of captcha. I think this would be easier in javascript, so yes I am in the right section.
__________________
www.nonamesite.forumotion.com
NO-NAME!
tonynoname123 is offline   Reply With Quote
Old 12-19-2009, 04:26 AM   PM User | #2
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,763
Thanks: 29
Thanked 452 Times in 446 Posts
jmrker will become famous soon enough
Question More information please ...

Quote:
Originally Posted by tonynoname123 View Post
Does anyone have a script, that can display a random image of the images I select?I'm going to use it for a type of captcha. I think this would be easier in javascript, so yes I am in the right section.
Clarification please ...

Where are the images coming from?
How are you getting the "images I select?"
Does the random display occur only once when page is loaded?
Do you have any sample starting code to show position, layouot, etc.?
jmrker is offline   Reply With Quote
Old 12-19-2009, 04:54 AM   PM User | #3
tonynoname123
New Coder

 
Join Date: Nov 2009
Location: www.nn11.darkbb.com
Posts: 40
Thanks: 2
Thanked 0 Times in 0 Posts
tonynoname123 is an unknown quantity at this point
sorry, I want the images from a url, I just paste the url into the source code as src="URL" yes only once per load, no, I don't have any sample codes...they're from my forum.
__________________
www.nonamesite.forumotion.com
NO-NAME!

Last edited by tonynoname123; 12-19-2009 at 04:57 AM.. Reason: none
tonynoname123 is offline   Reply With Quote
Old 12-19-2009, 07:49 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
This should meet your needs:-

Code:
<img  id = "captchaImage" width = "150" height = "150" >

<script type = "text/javascript">

var imgArray = ['One.gif','Two.gif','Three.gif','Four.gif','Five.gif', 'Six.gif', 'Seven.gif', 'Eight.gif', 'Nine.gif'];
function randOrd(){return (Math.round(Math.random())-0.5)}
imgArray.sort(randOrd);
alert (imgArray);  // FOR TESTING
var len = imgArray.length;
var count = 0;

function rotate() {
document.getElementById("captchaImage").src = imgArray[count];
count++;
if (count>=len) {count = 0}
var tcaptchaImage = window.setTimeout("rotate()", 5000);  // 5 seconds
}

rotate();

</script>
If you want to use URLs for the images, simply make your imageArray a list of the relevent URLs. If one image only is to be shown at page load then obviously the rotate() function is redundant. All you need is
document.getElementById("captchaImage").src = imgArray[0];


Quizmaster: What is the meaning of the French expression "coup de grâce"?
Contestant: Lawnmower.

Last edited by Philip M; 12-19-2009 at 08:35 AM..
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
tonynoname123 (12-20-2009)
Old 12-19-2009, 01:13 PM   PM User | #5
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,763
Thanks: 29
Thanked 452 Times in 446 Posts
jmrker will become famous soon enough
Smile If you snooze, you lose ...

Well, it looks like 'Philip M' codes in the UK while I'm sleeping in the US
but his suggestion is pretty close to what I would have done.
jmrker is offline   Reply With Quote
Old 12-20-2009, 04:02 AM   PM User | #6
tonynoname123
New Coder

 
Join Date: Nov 2009
Location: www.nn11.darkbb.com
Posts: 40
Thanks: 2
Thanked 0 Times in 0 Posts
tonynoname123 is an unknown quantity at this point
Perfect! Thanks! You can see a demo of what I used it for at www.1836.tk
__________________
www.nonamesite.forumotion.com
NO-NAME!

Last edited by tonynoname123; 12-20-2009 at 04:37 AM..
tonynoname123 is offline   Reply With Quote
Old 12-20-2009, 10:52 AM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
I would suggest that you make your images rather larger and more legible for the benefit of users with less-than-perfect sight.
Philip M is offline   Reply With Quote
Old 12-21-2009, 11:44 AM   PM User | #8
tonynoname123
New Coder

 
Join Date: Nov 2009
Location: www.nn11.darkbb.com
Posts: 40
Thanks: 2
Thanked 0 Times in 0 Posts
tonynoname123 is an unknown quantity at this point
ok, I'll do that.
__________________
www.nonamesite.forumotion.com
NO-NAME!
tonynoname123 is offline   Reply With Quote
Reply

Bookmarks

Tags
captcha, images, javascript, random, script

Jump To Top of Thread


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

Forum Jump


All times are GMT +1. The time now is 03:31 AM.


Advertisement
Log in to turn off these ads.