Undefined variable |
Undefined variable |
slantt |
Dec 24 2011, 06:04 PM
Post
#1
|
Newbie Group: Members Posts: 18 Joined: 16-November 11 Member No.: 15,867 |
I have a variable that is being flagged as undefined even though I've used it in previous routines in the same way in the same script. The basic script is as follows:
yrix = yrix + 1; yrstr = yrs[yrix]; // get to a specific place in an array mthinx = 0; mthstr = yrstr[mthinx]; // get to a specific place in the picked array I'm being told yrstr is 'undefined' in the 'mthstr = yrstr[mthinx]' statement. At entry to this routine yrstr has been used many times. So I thought something going on with yrix. At entry, yrix = 0 and I bump it by one so yrix equals 01, both of which I prove by document.write of the values at entry and after the bump by one. The validator didn't pick up anything . When I run it through MS debugger I'm told yrstr is null or not an object. Interesting thing is if I substitute 01 for yrix in the 'yrstr = yrs[yrix] statement so that yrstr = yrs[01] everything works. And if I set yrix = 1 instead of bumping it it also works fine. I have a work-around but I'd like to know what caused the undefined error. Jim This post has been edited by slantt: Dec 24 2011, 06:12 PM |
slantt |
Dec 24 2011, 06:11 PM
Post
#2
|
Newbie Group: Members Posts: 18 Joined: 16-November 11 Member No.: 15,867 |
I have a variable that is being flagged as undefined even though I've used it in previous routines in the same way in the same script. The basic script is as follows: yrix = yrix + 1; yrstr = yrs[yrix]; // get to a specific place in an array mthinx = 0; mthstr = yrstr[mthinx]; // get to a specific place in the picked array I'm being told yrstr is 'undefined' in the 'mthstr = yrstr[mthinx]' statement. At entry to this routine yrstr has been used many times. So I thought something going on with yrix. At entry, yrix = 0 and I bump it by one so yrix equals 01, both of which I prove by document.write of the values at entry and after the bump by one. The validator didn't pick up anything . When I run it through MS debugger I'm told yrstr is null or not an object. Interesting thing is if I substitute 01 for yrix in the 'yrstr = yrs[yrix] statement so that yrstr = yrs[01] everything works. And if I set yrix = 1 instead of bumping it it also works fine. I have a work-around but I'd like to know what caused the undefined error. script is at www.185talltimbers.info/date-test Jim Never mind - I found the problem. When I first set up yrix I turned it into a string value and it was being used the first time after that transfiguration. ooops...my bad.. Jim This post has been edited by slantt: Dec 24 2011, 06:12 PM |
Lo-Fi Version | Time is now: 9th June 2024 - 10:24 PM |