473,497 Members | 2,051 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript help required

2 New Member
I am currently working on a photo gallery which loads in images on the fly. upon the page loading, it scans the directory in PHP and builds an array of the image names in a JavaScript Array format i.e. Array("01.jpg', "02.jpg", ...)

I am new to using Javascript so don't really know the terms for things.

I have two navigation cursors which then cycle through the array.

What I want is to be able to display the image number and the total number of images for each image, and obviously change it as the image changes. i.e. this is image 1 of 10, which changes with the image

I have done this as a seperate function, though i don't know if it works like this, or if there is a more simple way of printing the index order of the array.

the script appears below

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="JavaScript">
  2. <!--
  3. // test the browser to make sure it's ok
  4. var browserName = navigator.appName;
  5. var browserVer = parseInt(navigator.appVersion);
  6. var browserOK = (((browserName == "Netscape") && (browserVer >= 3)) || 
  7.     ((browserName == "Microsoft Internet Explorer") && (browserVer >= 4)));
  8.  
  9. // URLs of images in slide show
  10. var slideURL = <?php echo ($img_list); ?>
  11. // delay between slides (in milliseconds)
  12. var slideDelay = 100000;
  13. // Index of the current slide
  14. var curSlide = -1;
  15. // timeout id for the current setTimeout command
  16. var curTimeout;
  17. var picTotal = <?php echo ($i-2); ?>;
  18. var curPic = 1;
  19.  
  20. function showSlide() {
  21.     if (browserOK) {
  22.         // alert(slideURL.length);
  23.         curSlide = ((curSlide + 1) % slideURL.length);
  24.         // alert(curSlide);
  25.         document.images["slideImg"].src = slideURL[curSlide];
  26.         curTimeout = setTimeout("showSlide()", slideDelay);
  27.     } else {
  28.         // show an error message for older browsers
  29.         alert("This page requires Netscape 3.0+ or IE 4.0+");
  30.     }
  31. }
  32. function increment_picNum()
  33. {
  34.     if (curPic < picTotal)
  35.         {
  36.             curPic= (curPic+1);
  37.         }
  38.     else
  39.         {
  40.             curPic=1;
  41.         }
  42.     var curPic=document.getElementById("pic_number");
  43. }
  44.  
  45. function decrement_picNum()
  46. {
  47.     if (curPic>1)
  48.         {
  49.             curPic=(curPic-1);
  50.         }
  51.     else
  52.         {
  53.             curPic=picTotal;
  54.         }
  55.     var curPic=document.getElementById("pic_number");
  56. }
  57.  
  58.  
  59. //function of one cursor
  60. function goNext() {
  61.     if (browserOK){
  62.         clearTimeout(curTimeout);
  63.         showSlide();
  64.         increment_picNum();
  65.     }
  66. }
  67. //function of the other
  68. function goPrev() {
  69.     if (browserOK) {
  70.         clearTimeout(curTimeout);
  71.         curSlide = (((curSlide - 2) + slideURL.length) % slideURL.length);
  72.         showSlide();
  73.         decrement_picNum();
  74.     }
  75. }
  76. // -->
  77. </SCRIPT>

The filenames are indexed as above.

I've been scratching my head for hours on this one, please help!
May 26 '06 #1
2 1888
Banfa
9,065 Recognized Expert Moderator Expert
You hold the picture number variable curPic and alter it using increment_picNum and decrement_picNum.

this is however completely unneccessary, the picture number is already available in the variable curSlide (picture number = curSlide+1).

Remove all references to

increment_picNum
decrement_picNum
curPic
picTotal

in showSlide add a line similar to

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("Subtitle").innerHtml = "Picture " + (curSlide+1) + " of " + slideURL.length;
  2.  
and in the html add

[html]
<div id="Subtitle"><div>
[/html]

close to the slideImg element unless of course your pic_number element is holding that position :D.
May 26 '06 #2
michaelmaud
2 New Member
You hold the picture number variable curPic and alter it using increment_picNum and decrement_picNum.

this is however completely unneccessary, the picture number is already available in the variable curSlide (picture number = curSlide+1).

Remove all references to

increment_picNum
decrement_picNum
curPic
picTotal

in showSlide add a line similar to

Expand|Select|Wrap|Line Numbers
  1. document.getElementById("Subtitle").innerHtml = "Picture " + (curSlide+1) + " of " + slideURL.length;
  2.  
and in the html add

[html]
<div id="Subtitle"><div>
[/html]

close to the slideImg element unless of course your pic_number element is holding that position :D.
Thanks that works like a dream now, the only slight modification was the innerHtml should be innerHTML

Thanks again for that
May 30 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
4857
by: AnnMarie | last post by:
My JavaScript Form Validation doesn't work at all in Netscape, but it works fine in IE. I made some of the suggested changes which enabled it to work in IE. I couldn't make all the changes...
53
5653
by: Cardman | last post by:
Greetings, I am trying to solve a problem that has been inflicting my self created Order Forms for a long time, where the problem is that as I cannot reproduce this error myself, then it is...
2
1849
by: Cliff R. | last post by:
Hello, I have a form that has a few required fields and also an "agree to terms" checkbox that must be required. I have used Javascripts for both functions individually, but I need a little help...
7
1802
by: f1crazed | last post by:
Ok, The following html works wonderful in IE. It does not work in FireFox. Can someone please tell me the work around for FireFox to get this to work. HTML DOCUMENT: <html> <head>...
1
5398
by: Jorge Ponte | last post by:
hi I have a Web User Control (ascx) - lets call it "My_WUC" - in a Web form. In that WUC I want have a textbox and a button. I want to click on the button and open a popup (I use javascript for...
5
3710
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button....
8
3621
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
24
6283
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
22
2843
by: Dan Rumney | last post by:
Hi all, I've been writing Javascript for quite a while now and have, of late, been writing quite a lot of AJAX and AJAX-related code. In the main, my dynamically generated pages are created...
3
3903
by: nigelesquire | last post by:
Please help! I'm trying to clone and delete multiple rows with JavaScript. I need two delete buttons that work...! I only have one for now, but it's not working properly, the output count is...
0
7121
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6993
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7162
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7197
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5456
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4899
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
650
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.