[thelist] javascript "won't" subtract

Emma Jane Hogbin emmajane at xtrinsic.com
Sat Mar 8 12:12:01 CST 2003

On Sat, Mar 08, 2003 at 09:50:45AM -0800, Tom Dell'Aringa wrote:
> Emma, a few things. #1 - almost without exception you should never
> need to use the eval() method. For more on this read:

Yeah, it's very very rare that I use it. I added it in trying to figure
out if the math wasn't working or if it was something else.

> http://www.doxdesk.com/personal/posts/wd/20011010-eval.html

I don't understand what the big deal is from this post...but it's ok. As I
mentioned before, I wasn't sure if it was a math problem which is why I'd
added it in. I've removed that bit (although I haven't uploaded the file).

> Secondly, when I have more than two if statements I personally like
> to use the switch control structure, its much cleaner.

I personally don't like switch controls. I think it's because I didn't
start with C/C++ as my first programming language. Even so it still
doesn't really explain why what I've got isn't working. What you describe
sounds it's going to do exactly what I've already got except you'll be
using switch controls. I don't understand why that's different.

> Now, all you really need to do is kick up and down the number of your
> slide. It seems to me that the number slide the person should be on
> in the page is the same as your photo, this makes things easy. All
> you need is a counter, and then to call the number of the current
> photo. So your 'home' page is 0. When they click next you add one,
> previous, subtract one.

I already have this, although I'm doing it a little differently. I set in
the page:
<input type="hidden" name="nextVal" value="0" />

This means I can put the js in an external file and call it from a whole
bunch of different galleries.

> This is untested but should work. I'm not sure why you are using
> visibility, I didn't take much of a look into the page so I left it
> there. Also, not sure where you are hiding the previous one, but you
> could handle that here too.

At this point I'm not hiding the previous one. Next seems to work ok
without hiding the previous one (sort of -- it still peaks through). I'll
add that bit now.

thanks for your suggestions! I'm still stumped how why what I'm doing
isn't working. :/


I've left your script at the bottom just in case others have some comments
on my comments and want to refer back to what you did. :)

On Sat, Mar 08, 2003 at 09:50:45AM -0800, Tom Dell'Aringa wrote:
> So first when the page loads, set a variable to 0:
> <script>
> var slideCount = 0;
> Make sure you do this OUTSIDE your function. Then the function should
> be called by your buttons of course, and have each button send its
> purpose:
> <button name="next onclick="showImg('next');"> etc.
> Then the function:
> function showImg(whatToDo)
> {
>   switch(whatToDo)
>   {
>     case "start":
>     slideCount = 1;  //just go to 1
>     break;
>     case "next":
>     slideCount += 1;  //adding one to it
>     break;
>     case "previous":
>     slideCount -= 1;  //subtracting one from it
>     break;
>   }
>   var photo = document.getElementById('+slideCount+').style;
>   photo.display = "block";
>   photo.visibility = "visible";
> }
Emma Jane Hogbin
[[ 416 417 2868 ][ www.xtrinsic.com ]]

More information about the thelist mailing list