/    Sign up×
Community /Pin to ProfileBookmark

simple image viewer problem

I’m a newbie to javascript and im having a problem with an extremely simple script. It is supposed to be a simple image view so that when you click the next button it goes to the next image. It’s not working though and I’ve looked at it until im crosseyed. Can somebody help me out here?

<head>
<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<script type=”text/javascript”>
var name=”xmas05″
var imgCount = 61
var pics[] = new Array(imgCount)
var start = null
var counter = 0

for(i = 1; i <= imgCount; i++)
{
pics[i] = new Image()
pics[i].src = name+”/pic”+i+”.jpg”
}

function changef()
{
counter ++

document.getElementById(“slide”).src = pics[counter].src
if(counter == imgCount)
counter = 0
}
}

function changeb()
{
counter —
document.getElementById(“slide”).src = pics[counter].src
if(counter == imgCount)
counter = 0
}
}

</script>
</head>

<body>
<img src=”../Graphics/backbutton.gif” width=”40″ height=”49″ border=”0″ onClick=”changeb()”>

<img src=”../Graphics/playbutton.gif” width=”40″ height=”49″ border=”0″ onClick=”changef()”>

<img src=”xmas05/pic1.jpg” id=”slide” />

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@James_GatkaJun 19.2006 — 
-----
Copy linkTweet thisAlerts:
@phpnoviceJun 19.2006 — I don't really see anything wrong with the code. You'd need to either check for error messages on your end or supply a live link so I can check out the operation of your page. I do notice, though, that you have no DOCTYPE and you're using the following:

<script type="text/javascript">

Without the DOCTYPE, IE will not execute JavaScript that is not indicated as follows:

<script language="javascript">
Copy linkTweet thisAlerts:
@porkyJun 19.2006 — Hello Jason,

try the code below

[code=html]<head>
<title>1Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<head>

<script type="text/javascript">
var name="xmas05";


var imgCount = 61;
var pics = new Array(imgCount);
var start = null;
var counter = 1;



for(i = 1; i <= imgCount; i++) {
pics[i] = new Image();
pics[i].src = name+"/pic"+i+".jpg";
}

function changef() {

counter++;
if(counter > imgCount) {
counter = 1;
}
document.getElementById("slide").src = pics[counter].src;


}

function changeb() {


counter--;

if(counter <= 0) {
counter = imgCount;
}

document.getElementById("slide").src = pics[counter].src;



}

</script>
</head>

<body>
<img src="../Graphics/backbutton.gif" width="40" height="49" border="0" onClick="changeb()">

<img src="../Graphics/playbutton.gif" width="40" height="49" border="0" onClick="changef()">

<img src="xmas05/pic1.jpg" id="slide" />

</body>
</html>[/code]
Copy linkTweet thisAlerts:
@phpnoviceJun 19.2006 — live link

http://www.thestompingrounds.com/pictures/slidetemplate.htm[/QUOTE]

That page produces an error message. This:

var pics[] = new Array(imgCount)

should be this:

var pics = new Array(imgCount)
Copy linkTweet thisAlerts:
@jasonlg3dauthorJun 19.2006 — Ok tried all of those suggestions/fixes and it still does nothing. The live link is updated. BTW how to you see errors on a page in firefox?
Copy linkTweet thisAlerts:
@jasonlg3dauthorJun 19.2006 — Porky!

That got it! Thank you. Thanks to all who helped out on this one.
×

Success!

Help @jasonlg3d spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...