2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by Taywin
0

I'm not sure if the problem is actually from your script. I don't know how your script function in the page, so it is difficult to say what causes it.

PS: Your script is very lengthy. You could use a loop to do the bar1 to bar6 portion outside the "switch" statement and it would be cleaner. (I am guessing your first part of bar1 in case 1 is incorrect.)

// all bar1 to bar6 display are related to imgNum
for (var i=1; i<=6; i++) {
  // note! imgNum must be a number or it will fail
  if (i==imgNum) { document.getElementById("bar"+i).src="images/bar.jpg" }
  else { document.getElementById("bar"+i).src="images/bar2.jpg" }
}

switch(imgNum) {
  case 1:
  if(groupNum==1) { document.getElementById("full").src="images/tanks2.jpeg"; {
  else { document.getElementById("full").src="images/tanks3.jpg"; }
  break;

  case 2:
  if(groupNum==1) { document.getElementById("full").src="images/tanks2.jpeg"; }
  else { document.getElementById("full").src="images/tanks4.jpg"; }
  break;

  case 3:
  if(groupNum==1) { document.getElementById("full").src="images/house1.jpeg"; }
  else { document.getElementById("full").src="images/motors.jpg"; }
  break;

  case 4:
  if(groupNum==1) { document.getElementById("full").src="images/house2.jpeg"; }
  else { document.getElementById("full").src="images/controls.jpg"; }
  break;

  case 5:
  if(groupNum==1) { document.getElementById("full").src="images/platform1.jpeg"; }
  else { document.getElementById("full").src="images/motors2.jpg"; }
  break;

  case 6:
  if(groupNum==1) { document.getElementById("full").src="images/fence.png"; }
  else { document.getElementById("full").src="images/field.jpg"; }
  break;
}
// The line below decreases imgNum value by 1 if and only if imgNum value
// is greater than 1 (the first image number); otherwise, it keeps statying
// at 1.
// If you do not understand why the script looks like that, please read about
// ternary statement.
imgNum = (imgNum>1) ? (imgNum-1) : 1

document.getElementById("numfield").value=imgNum;

Edited by Taywin

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.