[Javascript] variable undefined problem

hypersdc at cox.net hypersdc at cox.net
Wed May 28 00:31:10 CDT 2003


I still have the increment and variable undefined problem.

Here is my latest revision of the code:

var i = 0;
var itemCheck = item0; 
while(window.itemCheck) 
{ 

x = "item" + i;
itemCheck =eval(x);

document.write("<A HREF=" + itemCheck + ">" + itemCheck + "<BR></A>" );

  i++; 
} 


Any help would be appreciated as this one is driving me crazy.

The .js file that I'm getting the variables from has 2 items in it currently. 
var item0 = "files/file1.html";
var item1 = "files/file2.html";

Later it will have an unknown amount (that's why I need the while statement).

Thanks in advance,
hyper
  ----- Original Message ----- 
  From: Walter Torres 
  To: [JavaScript List] 
  Sent: Saturday, May 24, 2003 1:10 PM
  Subject: RE: [Javascript] variable undefined problem


  sure, increament *after* you get the item needed.

  You are doing it *before*

  This means you will *never* get 'item0' and you will always ask for ONE past
  the end.

  walter


  > -----Original Message-----
  > From: javascript-bounces at LaTech.edu
  > [mailto:javascript-bounces at LaTech.edu]On Behalf Of hypersdc at cox.net
  > Sent: Friday, May 23, 2003 11:48 AM
  > To: [JavaScript List]
  > Subject: Re: [Javascript] variable undefined problem
  >
  >
  > Ok. But how should I fix that. Any recommendations?
  > I'm trying to get the variable values from the external file
  > without knowing
  > how many items are in the list.
  >
  > Thanks
  > ----- Original Message -----
  > From: "Rodney Myers" <rodney at aflyingstart.net>
  > To: "[JavaScript List]" <javascript at LaTech.edu>
  > Sent: Saturday, May 24, 2003 2:10 AM
  > Subject: Re: [Javascript] variable undefined problem
  >
  >
  > > Hello,
  > >
  > > As the while loop starts with a valid itemCheck variable it should cycle
  > > until the last valid variable.
  > > But inside the loop you have
  > >
  > > x = "item" + i;
  > > itemCheck =eval(x);
  > >
  > >
  > > if itemN was the last valid item, and so permitted entry to the loop
  > > the N+1 is guaranteed to be undefined.
  > >
  > > hth
  > >
  > > Rodney
  > >
  > >
  > > hypersdc at cox.net wrote:
  > >
  > > >I'm having problems with a variable undefined error.
  > > >
  > > >I'm grabbing a set of variables from a file (.js file). I'm cycling
  > through
  > > >the variables with a while statement. The problem I'm having
  > is the last
  > > >variable is getting an undefined. How can I fix the code so
  > this doesn't
  > > >happen.
  > > >
  > > >//Start Code:
  > > >
  > > >var i = 0;
  > > >var itemCheck = item0;
  > > >while(window.itemCheck)
  > > >{
  > > >
  > > >  document.write("<A HREF=" + itemCheck + ">" + itemCheck +
  > "<BR></A>" );
  > > >
  > > >   i++;
  > > >x = "item" + i;
  > > >itemCheck =eval(x);
  > > >
  > > >if (typeof eval(x) == 'undefined')
  > > >    alert('2 Undefined');
  > > >else
  > > >    alert('2 okay');
  > > >itemCheck =eval(x);
  > > >
  > > >
  > > >}
  > > >
  > > >
  > > >//End code
  > > >
  > > >//js content
  > > >var item0 = "name 1";
  > > >var item1 = "name 2";
  > > >
  > > >//end js file content
  > > >
  > > >Thanks in advance
  > > >
  > > >_______________________________________________
  > > >Javascript mailing list
  > > >Javascript at LaTech.edu
  > > >https://lists.LaTech.edu/mailman/listinfo/javascript
  > > >
  > > >
  > > >
  > >
  > > --
  > >
  > > PS. I now have resale rights for Mike Chen's
  > > BizAutomator. If you have to answer routine
  > > email queries from your sites or mailings then
  > > you will find this simple-to-use program invaluable.
  > > http://www.BizAutomator.co.uk
  > >
  > >
  > >
  > >
  > >
  > >
  > >
  > >
  > > _______________________________________________
  > > Javascript mailing list
  > > Javascript at LaTech.edu
  > > https://lists.LaTech.edu/mailman/listinfo/javascript
  >
  > _______________________________________________
  > Javascript mailing list
  > Javascript at LaTech.edu
  > https://lists.LaTech.edu/mailman/listinfo/javascript


  _______________________________________________
  Javascript mailing list
  Javascript at LaTech.edu
  https://lists.LaTech.edu/mailman/listinfo/javascript
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20030527/31566ea2/attachment.htm>


More information about the Javascript mailing list