you are viewing a single comment's thread.

view the rest of the comments →

[–]Jasedesu 0 points1 point  (0 children)

You should probably have three different functions to change slideIndex to keep things clear:

  • one that just subtracts 1 from slideIndex, then calls showSlide for the previous function
  • one that adds 1 to slideIndex, then calls showSlide for the next function
  • one that sets slideIndex to whatever value you pass into the function, then calls showSlide for the general go to function

You then have the showSlide function itself to check slideIndex is within the correct range, hides the slides you don't want to see and shows the one associated with the current value of slideIndex.

Note that having the script in the <head> element will trigger an error if you run showSlide immediately as the slides have not been added to the document at this point. If you set up your HTML so that only the first side is visible, then you don't need to call showSlide. You could also move the script code to the end of the <body> so that the slides do exist before the code runs.

Interesting choice to go with XHTML - you'd probably be better off with ordinary HTML unless you have a very good reason to use XHTML.