I have this code right here. The array starts with one item in it but i have dynamic links in the front end page that say this:
<a href="#" onClick="javascript:testItems('image2')">test</a>
<a href="#" onClick="javascript:testItems('image3')">test</a>
<a href="#" onClick="javascript:testItems('image4')">test</a>
Not all pages will have an image2 or image 3 or 4 so everytime the link is clicked, i need to add the item to the array and i get it to add but once i click the item again, it's re-entering and i can see how it's entering but i need to basically say something like "if the array doesnt have the value, then add it to the array". I appreciate any help.
var newArray =new Array();
newArray[0] = "image1"
function testItems(id)
{
for (i=0;i<=newArray.length-1;i++)
{
if (newArray != id)
{
newArray[newArray.length] = id;
}
alert(newArray);
}
}
<a href="#" onClick="javascript:testItems('image2')">test</a>
<a href="#" onClick="javascript:testItems('image3')">test</a>
<a href="#" onClick="javascript:testItems('image4')">test</a>
Not all pages will have an image2 or image 3 or 4 so everytime the link is clicked, i need to add the item to the array and i get it to add but once i click the item again, it's re-entering and i can see how it's entering but i need to basically say something like "if the array doesnt have the value, then add it to the array". I appreciate any help.
var newArray =new Array();
newArray[0] = "image1"
function testItems(id)
{
for (i=0;i<=newArray.length-1;i++)
{
if (newArray != id)
{
newArray[newArray.length] = id;
}
alert(newArray);
}
}