[thelist] javascript "won't" subtract

Erik Mattheis gozz at gozz.com
Sat Mar 8 16:44:00 CST 2003


A couple things, don't know which or both may be causing the problems
...

JavaScript isn't a typed language, so it will treat a number as a
number when needed and as a string when needed - so no need to use
parseInt() (that's not the problem but it's unneeded.

JavaScript variables cannot start with numbers and eval(slide - 1)
looks to me like it might be asking javascript to think of a number as
a variable.

Also, I believe the same naming convention of not starting with a digit
applies to the id and name attributes in HTML ... so rename your
attributes like "slide1" and try this:

function showImg(
	var img = document.forms[0].nextVal.value;

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

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

}

<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="text" name="nextVal" value="0" />
<input type="text" name="img" value="" />
</form>
On Saturday, March 8, 2003, at 11:28  AM, Emma Jane Hogbin wrote:

> Does anyone see anything obvious in what I've done? I've been testing
> it
> in Phoenix (linux) and Mozilla (windows
-----------------------
Erik Mattheis
GoZz Digital
<http://goZz.com/>
Flash and ColdFusion Development
Minneapolis, MN
-----------------------




More information about the thelist mailing list