Slight probs with a javascript
08-06-2006, 20:27
|
#1
|
|
Inactive
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
|
Slight probs with a javascript
hey people,
I have got a small page that I am showing some pics that I took today, when I was out cycling over the local hills.
I have the page working fine, like a back and forward button and the images smaller than they should be so they fit on the screen better than when they were big.
this part works fine.
but I also want to put the big files on show as well if someone clicks the smaller image.
now, there is only one page so I am using javascript to incrememnt a number and change the picture accordingly, this part is fine.
but I am trying to get the image and find the same one but in larger size,
does this make sense?
I have a cycle folder with the html file and the smaller images, and I have another folder (Large) with the larger images.
here is the code but the red is the problems:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type="text/javascript">
var numImages = 21; //change this number to the exact number of pics is taken
var currentImage = 1;
var imageName = "pic";
var imageFile = ".JPG";
var prefix = "Large/";
function switchImage()
{
currentImage++;
if(currentImage > numImages)currentImage = 1;
var thePic = imageName + currentImage + imageFile;
document.getElementById("theImg").src = thePic;
document.getElementById("theImg").alt = thePic;
}
function goBackImage()
{
--currentImage;
if(currentImage < 1)currentImage = numImages;
var thePic = imageName + currentImage + imageFile;
document.getElementById("theImg").src = thePic;
document.getElementById("theImg").alt = thePic;
}
function showBigPic()
{
var theBigPic = prefix + imageName + currentImage + imageFile;
document.getElementById("theBigImg").src = theBigPic;
document.getElementById("theBigImg").alt = theBigPic;
}
</script>
<style type="text/css">
body {background-color:#000000; color:#FFFFFF; text-align:center;}
</style>
</HEAD>
<body>
<form>
<input type="button" value="Back" onClick="goBackImage()">
<input type="button" value="Forward" onClick="switchImage()"></form>
<a href="Large/pic1.JPG" id="theBigImg" onClick="showBigPic()">
<img src="pic1.JPG" id="theImg">
</a>
</BODY>
</HTML>
ik
|
|
|
08-06-2006, 20:38
|
#2
|
|
cf.mega poster
Join Date: Mar 2006
Location: Oslo, Norway.
Age: 37
Services: Canal Digital: 50/10
Posts: 7,577
|
Re: Slight probs with a javascript
Shouldn't "var prefix = "Large/";" be "var prefix = "/Large/";"
Otherwise you aren't referencing another directory at all?
|
|
|
08-06-2006, 20:41
|
#3
|
|
Inactive
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
|
Re: Slight probs with a javascript
Quote:
|
Originally Posted by Druchii
Shouldn't "var prefix = "Large/";" be "var prefix = "/Large/";"
Otherwise you aren't referencing another directory at all?
|
ok, see what your trying to say, but still does not help with my problem.
say I click the button to get to pic 5 then I want to click the pic and go to the bigger pic, but the same pic.
all the pics are named the same (pic1.JPG, pic2.JPG, pic3.JPG, etc) but in different folders
at the moment when I click any small pic, it takes me to pic1.JPG instead of, say pic5.JPG.
ik
|
|
|
08-06-2006, 21:05
|
#4
|
|
Inactive
Join Date: Jun 2003
Location: London way
Age: 50
Services: Sarcasm
Posts: 8,376
|
Re: Slight probs with a javascript
Replace
Code:
document.getElementById("theBigImg").src = theBigPic;
document.getElementById("theBigImg").alt = theBigPic;
with
Code:
document.getElementById("theImg").src = theBigPic;
document.getElementById("theImg").alt = theBigPic;
You're trying to set the properties of the html link not the image
---------- Post added at 21:05 ---------- Previous post was at 21:04 ----------
and replace the
Code:
<a href="Large/blah">
with
you don't need to, it's just tidier
|
|
|
08-06-2006, 21:32
|
#5
|
|
Inactive
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
|
Re: Slight probs with a javascript
Quote:
|
Originally Posted by Mr_love_monkey
Replace
Code:
document.getElementById("theBigImg").src = theBigPic;
document.getElementById("theBigImg").alt = theBigPic;
with
Code:
document.getElementById("theImg").src = theBigPic;
document.getElementById("theImg").alt = theBigPic;
You're trying to set the properties of the html link not the image
|
well I tried that earlier but then, when I click the small image, nothing happens, it does not go to the big pic.
ik
|
|
|
08-06-2006, 21:36
|
#6
|
|
Inactive
Join Date: Jun 2003
Location: London way
Age: 50
Services: Sarcasm
Posts: 8,376
|
Re: Slight probs with a javascript
Quote:
|
Originally Posted by ikthius
well I tried that earlier but then, when I click the small image, nothing happens, it does not go to the big pic.
ik
|
Weird, it works here.
what happens if you do alert(document.getElementById("theImg").width) in that call ?
|
|
|
08-06-2006, 21:47
|
#7
|
|
Inactive
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
|
Re: Slight probs with a javascript
Quote:
|
Originally Posted by Mr_love_monkey
Quote:
|
Originally Posted by ikthius
well I tried that earlier but then, when I click the small image, nothing happens, it does not go to the big pic.
ik
|
Weird, it works here.
what happens if you do alert(document.getElementById("theImg").width) in that call ?
|
clicking on the small image I get 800.
but I want to click that image to get to the bigger pic.
ik
|
|
|
08-06-2006, 22:00
|
#8
|
|
Inactive
Join Date: Jun 2003
Location: London way
Age: 50
Services: Sarcasm
Posts: 8,376
|
Re: Slight probs with a javascript
Quote:
|
Originally Posted by ikthius
clicking on the small image I get 800.
but I want to click that image to get to the bigger pic.
ik
|
hmm.. well that shows that you are finding the image object..
very odd.. the large image works on mine, but the paging back and forwards doesn't... hmmm
---------- Post added at 22:00 ---------- Previous post was at 21:57 ----------
Have you tried it under IE? - I'm running firefox and get the issues mentioned above, but it works ok under IE
|
|
|
08-06-2006, 22:01
|
#9
|
|
Inactive
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
|
Re: Slight probs with a javascript
Quote:
|
Originally Posted by Mr_love_monkey
Quote:
|
Originally Posted by ikthius
clicking on the small image I get 800.
but I want to click that image to get to the bigger pic.
ik
|
hmm.. well that shows that you are finding the image object..
very odd.. the large image works on mine, but the paging back and forwards doesn't... hmmm
|
if it does not buttons do not work, change:
Code:
document.getElementById("theImg").src = theBigPic;
document.getElementById("theImg").alt = theBigPic;
to
Code:
document.getElementById("theBigImg").src = theBigPic;
document.getElementById("theBigImg").alt = theBigPic;
ik
EDIT: yip just tried it on IE and it works, but I would like it to work on FF too, as I and many other people use FF
EDIT: it now works in FF too, cheers
this is the end code to make it all work
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script type="text/javascript">
var numImages = 21; //change this number to the exact number of pics is taken
var currentImage = 1;
var imageName = "pic";
var imageFile = ".JPG";
var prefix = "Large/";
function switchImage()
{
currentImage++;
if(currentImage > numImages)currentImage = 1;
var thePic = imageName + currentImage + imageFile;
document.getElementById("theImg").src = thePic;
document.getElementById("theImg").alt = thePic;
}
function goBackImage()
{
--currentImage;
if(currentImage < 1)currentImage = numImages;
var thePic = imageName + currentImage + imageFile;
document.getElementById("theImg").src = thePic;
document.getElementById("theImg").alt = thePic;
}
function showBigPic()
{
var theBigPic = prefix + imageName + currentImage + imageFile;
document.getElementById("theImg").src = theBigPic;
document.getElementById("theImg").alt = theBigPic;
}
</script>
<style type="text/css">
body {background-color:#000000; color:#FFFFFF; text-align:center;}
</style>
</HEAD>
<body>
<form>
<input type="button" value="Back" onClick="goBackImage()">
<input type="button" value="Forward" onClick="switchImage()"></form>
<a href="#" id="theBigImg" onClick="showBigPic()">
<img src="pic1.JPG" id="theImg">
</a>
</BODY>
</HTML>
|
|
|
08-06-2006, 22:03
|
#10
|
|
Inactive
Join Date: Jun 2003
Location: London way
Age: 50
Services: Sarcasm
Posts: 8,376
|
Re: Slight probs with a javascript
Quote:
|
Originally Posted by ikthius
if it does not buttons do not work, change:
Code:
document.getElementById("theImg").src = theBigPic;
document.getElementById("theImg").alt = theBigPic;
to
Code:
document.getElementById("theBigImg").src = theBigPic;
document.getElementById("theBigImg").alt = theBigPic;
ik
|
but your code for the buttons doesn't even call that function?
|
|
|
08-06-2006, 22:07
|
#11
|
|
Inactive
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
|
Re: Slight probs with a javascript
Quote:
|
Originally Posted by Mr_love_monkey
[<snip>
but your code for the buttons doesn't even call that function?
|
it was not the functions for the buttons, but for the showBigImg()
ik
|
|
|
08-06-2006, 22:15
|
#12
|
|
Inactive
Join Date: Jun 2003
Location: London way
Age: 50
Services: Sarcasm
Posts: 8,376
|
Re: Slight probs with a javascript
Quote:
|
Originally Posted by ikthius
EDIT: yip just tried it on IE and it works, but I would like it to work on FF too, as I and many other people use FF
EDIT: it now works in FF too, cheers
this is the end code to make it all work
|
Excellent, glad it works
|
|
|
08-06-2006, 23:02
|
#13
|
|
Inactive
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
|
Re: Slight probs with a javascript
After all of that, I don't have enough space on my site for the large pics.
oh well I have changed the code back so that the small pics show, and I have left the original one that worked, on my comp.
for anyone interested here are the pics I took today, and got burnt to a crisp.
ik
EDIT: if anyone likes some of the pics and want a bigger version, just pm me, but I know you wont, hehe
|
|
|
08-06-2006, 23:46
|
#14
|
|
Guest
|
Re: Slight probs with a javascript
really good pics, ik, that looks like a big climb, I just hope you chose a day when the wind was behind you
|
|
|
|
09-06-2006, 10:57
|
#15
|
|
Inactive
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
|
Re: Slight probs with a javascript
Quote:
|
Originally Posted by homealone
really good pics, ik, that looks like a big climb, I just hope you chose a day when the wind was behind you 
|
actually the wind, yesterday, hardly rose up at all gaz. it was absolutely roasting, hence in pain with sunburn now.
there are bigger pics if anyone wants!
ik
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT. The time now is 15:53.
|