Help - Search - Members - Calendar
Full Version: What's wrong with this JS?!
Invision Power Services > Community Forums > Community Web Design and Coding
Dimdum
This code is supposed to change a picture on the code. It does it okay one more time and only forward. It doen't do anything else!!!
why?!?!
CODE
        function pictures(stri)
         {
         var pics = new Array('images/women/maya/1_1.jpg', 'images/women/maya/1_2.jpg', 'images/women/maya/1_3.png', 'images/women/maya/1_4.jpg');
         var total = 0;
         var now = 0;
         for ( keyVar in pics)
          {
          if (keyVar == document.all.image.src)
           {
           now = total;
           }
          total = total + 1;
          }
         if (now == total) document.all.image.src = "images/"+pics[0];
         if (now == 0) document.all.image.src = pics[total];
         document.all.image.src = (stri == "next") ? pics[now+1] : pics[now-1];
         }

And this is the HTML:
CODE
<img src="images/women/maya/1_1.jpg" name="image"><br />
<div style="font-weight: none; height: 17px; vertical-align: middle;" nowrap>
             <p style="width: auto; float: right;">&nbsp;&nbsp;<a href="java script: pictures('next');">הבא</a></p>
             <p style="width: auto; float: left;"><a href="java script: pictures('privious');">קודם</a>&nbsp;&nbsp;</p>
             </div>
Dimdum
Thanks for the help.
The script should be this:
CODE
        function pictures(stri)
         {
         var pics = new Object();
         var total = -1;
         var now = 0;
         pics['0'] = "http://localhost/costumers/starpic/new/images/women/maya/1_1.jpg";
         pics['1'] = "http://localhost/costumers/starpic/new/images/women/maya/1_2.jpg";
         pics['2'] = "http://localhost/costumers/starpic/new/images/women/maya/1_3.png";
         pics['3'] = "http://localhost/costumers/starpic/new/images/women/maya/1_4.jpg";
         for ( keyVar in pics)
          {
          if (pics[keyVar] == document.all.image.src)
           {
           now = total + 1;
           }
          total = total + 1;
          }
         if (now == total && stri == "next") { document.all.image.src = pics['0']; }
         else if (now == 0 && stri == "privious") { document.all.image.src = pics[total]; }
         else { document.all.image.src = (stri == "next") ? pics[now+1] : pics[now-1]; }
         }
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.