Cable Forum

Cable Forum (https://www.cableforum.uk/board/index.php)
-   General IT Discussion (https://www.cableforum.uk/board/forumdisplay.php?f=19)
-   -   Slight probs with a javascript (https://www.cableforum.uk/board/showthread.php?t=48448)

ikthius 08-06-2006 20:27

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()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<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

Druchii 08-06-2006 20:38

Re: Slight probs with a javascript
 
Shouldn't "var prefix = "Large/";" be "var prefix = "/Large/";"

Otherwise you aren't referencing another directory at all?

ikthius 08-06-2006 20:41

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

Mr_love_monkey 08-06-2006 21:05

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

Code:

<a href="#">
you don't need to, it's just tidier

ikthius 08-06-2006 21:32

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

Mr_love_monkey 08-06-2006 21:36

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 ?

ikthius 08-06-2006 21:47

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

Mr_love_monkey 08-06-2006 22:00

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

ikthius 08-06-2006 22:01

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()">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" value="Forward" onClick="switchImage()"></form>
    <a href="#" id="theBigImg" onClick="showBigPic()">
        <img src="pic1.JPG" id="theImg">
    </a>
</BODY>
</HTML>


Mr_love_monkey 08-06-2006 22:03

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?

ikthius 08-06-2006 22:07

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

Mr_love_monkey 08-06-2006 22:15

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

ikthius 08-06-2006 23:02

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

homealone 08-06-2006 23:46

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 :)

ikthius 09-06-2006 10:57

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


All times are GMT. The time now is 16:07.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum