Jump to content

[SOLVED] javascript if statement(If object exists)


Guardian-Mage

Recommended Posts

I have a slideshow that is different than others. Part of it is it needs to be automated.

var slideLength = 27;

var lock = false;
var run;

var idvar = '001';

function changeImage(dir)
{
if (document.images)
     {
          curImg = curImg + dir;
	  
          if (curImg > slideLength)
          {
               curImg = 1;
          }
	  
          if (curImg < 1)
          {
               curImg = slideLength;
          }
	  
	  if (document.getElementById(curImg))
	  {
	  	var nextImage = document.getElementById(curImg).innerHTML;	  
	  }
	  else
	  {
	  	curImg++;
	  }
	  
          document.getElementById('slideshow').innerHTML = nextImage;
          document.getElementById('slide').value = curImg;
     }
}

 

This will take the content of a table and load it. But say I have objects with the ID 3,4,5,6,8 but no 7. My script needs to skip it. Part of what I have works. It will skip the number but than it says the nextImage is not defined. I need it so when it says

 

	  else
	  {
	  	curImg++;
	  }

It will than retry the if loop to see if the new object exists

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.