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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.