Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append to a list? 1

Status
Not open for further replies.

static786

Programmer
Feb 13, 2006
23
GB
I'm trying to create a lis for which every time the code is executed, it appends the new values to the end of the list. I've tried the following, and it does'nt work. Can someone provide suggestions. (for some reason it always equals null?)

if(listXY == null)
{
alert("list eq null");
var listXY=clickedX+","+clickedY;
}
else
{
alert("list eq summit");
listXY=","+listXY+","+clickedX+","+clickedY;
}

 
You need to declare your variable listXY as a global variable. Don't declare it local to the function...
Code:
var listXY = null; // outside the function

function somefunc() {
...
if(listXY == null)
{
  alert("list eq null");
  [s]var[/s] listXY=clickedX+","+clickedY;
}
else
{
  alert("list eq summit");
  listXY=","+listXY+","+clickedX+","+clickedY;
}
...
}

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top