...

View Full Version : javascript image question



stevmusik
12-24-2010, 07:24 AM
I was wondering if it was possible to get java to display images that have the same name but diff numbers like:

Soccer***

Displays;
Soccer001
Soccer002
Soccer003
Soccer004
.... So on and so forth.

Sorry the question isn't worded well lol

Philip M
12-24-2010, 08:56 AM
Yes, of course. Why do you think otherwise? :confused: All your images have different names, and those names may include numerals.

Be aware that Java and Javascript are entirely different programming languages, in spite of the confusingly similar names.



It is your responsibility to die() if necessary….. - PHP Manual

stevmusik
12-24-2010, 09:20 AM
I Sorry for not being clear lol. My brain wasn't working at the time. What I meant was: Is it possible to get javascript to automatically display all the images with a certain suffix. Example, I want it to display all images with "soccer" at the beginning of its name automatically. Is this possible? And if so how?

Philip M
12-24-2010, 09:38 AM
Suffix or prefix?

JavaScript cannot access the user's operating system or the Windows registry. So if you mean display all image files in a directory that begin with "soccer", the answer is no.

What you should do is make an array containing all the relevant files, e.g.
var myArray = ["soccer001.jpg", "soccer002.jpg", "soccer003.jpg"] // and so on
and then use script to select the one to be displayed. I assume you do not want to display them all at the same time.

You can do this using server-side scripting. See:-
http://www.javascriptkit.com/javatutors/externalphp2.shtml


All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

Logic Ali
12-25-2010, 06:34 AM
I Sorry for not being clear lol. My brain wasn't working at the time. What I meant was: Is it possible to get javascript to automatically display all the images with a certain suffix. Example, I want it to display all images with "soccer" at the beginning of its name automatically. Is this possible? And if so how?

It's not clear how you want the images displayed.

It is possible to do this provided that the script is supplied with the right parameters. This code will display one image at a time in a cycling slideshow.

The images displayed would be named "soccer1.jpg" - "soccer50.jpg" from the current folder. If any images in the sequence are unavailable, there should be no error.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Test</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>
<img src='soccer1.jpg' id='myImage' alt='image'>

<script type='text/javascript'>

function loadBySuffix( imageId, prefix, startSuffix, ext, limit, delay )
{
var pageImage = document.getElementById( imageId ),
sfx = startSuffix,
holder = document.createElement( 'img' );

holder.width = 0;
holder.height = 0;

document.body.appendChild( holder );

holder.onerror = function()
{
if( ++sfx > limit )
sfx = startSuffix;

setTimeout( function(){ holder.src = prefix + ( sfx ) + ext }, 1 );
}

holder.onload = function()
{
pageImage.src = this.src;
setTimeout( function(){ holder.onerror(); }, delay );
}

holder.src = prefix + startSuffix + ext;
}

loadBySuffix( 'myImage', 'soccer', 1, '.jpg', 50, 2000 );

</script>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum