dumbnoob Posted December 30, 2009 Share Posted December 30, 2009 Ok, I have a script, that when run, will cycle through the contents of an array, and when it reaches the end, will loop back to the beginning. However, if the variable used to determine its position has not been set on the page already, it doesn't run. I need a way to set the variable, only if it does not exist. My code below javascript: if (confpos==undefined){ confpos=0; } config=[1,2,4,7,12,16]; IT=(config[confpos]); alert (IT); confpos=++confpos; IT=(config[confpos]); if (IT==undefined){ confpos=1; } void(0); If I have previously punched javascript: confpos=0; void(0); into my address bar, the code will run fine, but, I need it to do what it's meant to, without me having to predefine confpos. In that, if confpos isn't set, then I need it to set it automatically, so that it will be able to run the rest of the script. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.