[thelist] javascript "won't" subtract

Emma Jane Hogbin emmajane at xtrinsic.com
Sat Mar 8 11:28:07 CST 2003


Hey Listees:

I have a very simple javascript. I don't want browser sniffers or anything
complicated. The weird thing is: it's being inconsistent. It's a very very
basic slide show. A bunch of divs hold images and one at a time I want to
show the divs.

The "start" button only works if I click it first, not second. And and the
previous button doesn't ever work. The next button only works if I click
it first and (or right after the first click of the start button). And
then works sequentially up. (But I can't use any of the other buttons in
the sequence.) The previous button never works.

http://queenwest.ca/lomo/emmajane/popnine1/

(Don't worry about the styles, I can figure those out later.)

Here's the script that I have in an external file:
function showImg(choice) {

        var img = parseInt(document.forms[0].nextVal.value);
        var slide;

        if (img <= 0) { slide = 1; }
        else if (choice == "start") { slide = 1; }
        else if (choice == "next") { slide = eval(img +1); }
        else if (choice == "prev") { slide = eval(img - 1); }

        var photo = document.getElementById(slide).style;
        photo.display = "block";
        photo.visibility = "visible";
        document.forms[0].nextVal.value = slide;
}

And here's the XHTML snippet that calls it:
<form>
<input onclick="showImg('prev');" type="button" name="back" value="previous image" />
<input onclick="showImg('start');" type="button" name="start" value="start" />
<input onclick="showImg('next');" type="button" name="next" value="next image" />
<input type="hidden" name="nextVal" value="0" />
</form>

Does anyone see anything obvious in what I've done? I've been testing it
in Phoenix (linux) and Mozilla (windows) with the same results (as
described above).

--
Emma Jane Hogbin
[[ 416 417 2868 ][ www.xtrinsic.com ]]



More information about the thelist mailing list