Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | Slight probs with a javascript

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > General IT Discussion

Slight probs with a javascript
Reply
 
Thread Tools
Old 08-06-2006, 20:27   #1
ikthius
Inactive
 
ikthius's Avatar
 
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
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
ikthius is offline   Reply With Quote
Advertisement
Old 08-06-2006, 20:38   #2
Druchii
cf.mega poster
 
Druchii's Avatar
 
Join Date: Mar 2006
Location: Oslo, Norway.
Age: 37
Services: Canal Digital: 50/10
Posts: 7,577
Druchii has a nice shiny star
Druchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny starDruchii has a nice shiny star
Re: Slight probs with a javascript

Shouldn't "var prefix = "Large/";" be "var prefix = "/Large/";"

Otherwise you aren't referencing another directory at all?
Druchii is offline   Reply With Quote
Old 08-06-2006, 20:41   #3
ikthius
Inactive
 
ikthius's Avatar
 
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
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
ikthius is offline   Reply With Quote
Old 08-06-2006, 21:05   #4
Mr_love_monkey
Inactive
 
Mr_love_monkey's Avatar
 
Join Date: Jun 2003
Location: London way
Age: 50
Services: Sarcasm
Posts: 8,376
Mr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny stars
Mr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny stars
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
Mr_love_monkey is offline   Reply With Quote
Old 08-06-2006, 21:32   #5
ikthius
Inactive
 
ikthius's Avatar
 
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
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
ikthius is offline   Reply With Quote
Old 08-06-2006, 21:36   #6
Mr_love_monkey
Inactive
 
Mr_love_monkey's Avatar
 
Join Date: Jun 2003
Location: London way
Age: 50
Services: Sarcasm
Posts: 8,376
Mr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny stars
Mr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny stars
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 ?
Mr_love_monkey is offline   Reply With Quote
Old 08-06-2006, 21:47   #7
ikthius
Inactive
 
ikthius's Avatar
 
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
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
ikthius is offline   Reply With Quote
Old 08-06-2006, 22:00   #8
Mr_love_monkey
Inactive
 
Mr_love_monkey's Avatar
 
Join Date: Jun 2003
Location: London way
Age: 50
Services: Sarcasm
Posts: 8,376
Mr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny stars
Mr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny stars
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
Mr_love_monkey is offline   Reply With Quote
Old 08-06-2006, 22:01   #9
ikthius
Inactive
 
ikthius's Avatar
 
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
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>
ikthius is offline   Reply With Quote
Old 08-06-2006, 22:03   #10
Mr_love_monkey
Inactive
 
Mr_love_monkey's Avatar
 
Join Date: Jun 2003
Location: London way
Age: 50
Services: Sarcasm
Posts: 8,376
Mr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny stars
Mr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny stars
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?
Mr_love_monkey is offline   Reply With Quote
Old 08-06-2006, 22:07   #11
ikthius
Inactive
 
ikthius's Avatar
 
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
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
ikthius is offline   Reply With Quote
Old 08-06-2006, 22:15   #12
Mr_love_monkey
Inactive
 
Mr_love_monkey's Avatar
 
Join Date: Jun 2003
Location: London way
Age: 50
Services: Sarcasm
Posts: 8,376
Mr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny stars
Mr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny stars
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
Mr_love_monkey is offline   Reply With Quote
Old 08-06-2006, 23:02   #13
ikthius
Inactive
 
ikthius's Avatar
 
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
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
ikthius is offline   Reply With Quote
Old 08-06-2006, 23:46   #14
homealone
Guest
 
Posts: n/a
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
  Reply With Quote
Old 09-06-2006, 10:57   #15
ikthius
Inactive
 
ikthius's Avatar
 
Join Date: Mar 2004
Location: Glasgow, Scotland
Services: anything for a new job
Posts: 4,165
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
ikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronzeikthius is cast in bronze
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
ikthius is offline   Reply With Quote
Reply

Thread Tools

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. The time now is 18:18.


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