0

confused: Not sure why this function works the first time but doesn't the second or third time. Any advice greatly appreciated. This is called with ul li tag onclick which sends an ajax get call to the database so the array can only contain upto 3 matching indexes. I should be able to urencode the array.join(' ') and send it to the server for pagination technique with ajax Get request, unfortunatley after the first round the array.join will produce 'art' 'art' 'silver'. Which I could break down on the server side with the php file but I would preffer that the array arrived as per the function. ie.
eather of the following

  • 'art'
  • 'art' 'art'
  • 'art' 'art' 'art'

not

  • 'art'
  • 'art' 'silver'
  • 'silver' 'art' 'silvergold'

Function Counter()

function counter()
{
if(count.length==1)
{
return;
}
else if(count.length==2 && count[0]!==count[1])
{
count.shift();
alert(count.join(' '));//Demonstrates flaw
}
else if(count.length==3 && count[0]!==count[1])
{
count.shift();
alert(count.join(' '));
}
else if(count.length==3 && count[1]!==count[2])
{
count.shift();
count.shift();
alert(count.join(' '));
}
else if(count.length>3)
{
count.shift();
alert(count.join(' '));
}
}

Not sure why it doesn't work beyond first time arround:eek:. Thanks again for any advice.

Edited by mike_2000_17: Fixed formatting

1
Contributor
2
Replies
3
Views
5 Years
Discussion Span
Last Post by Heinz Stapff
0

:confused: Not sure why this function works the first time but doesn't the second or third time. Any advice greatly appreciated. This is called with ul li tag onclick which sends an ajax get call to the database so the array can only contain upto 3 matching indexes. I should be able to urencode the array.join(' ') and send it to the server for pagination technique with ajax Get request, unfortunatley after the first round the array.join will produce 'art' 'art' 'silver'. Which I could break down on the server side with the php file but I would preffer that the array arrived as per the function. ie.
eather of the following

  • 'art'
  • 'art' 'art'
  • 'art' 'art' 'art'

not

  • 'art'
  • 'art' 'silver'
  • 'silver' 'art' 'silvergold'

Function Counter()

function counter()
{
if(count.length==1)
{
return;
}
else if(count.length==2 && count[0]!==count[1])
{
count.shift();
alert(count.join(' '));//Demonstrates flaw
}
else if(count.length==3 && count[0]!==count[1])
{
count.shift();
alert(count.join(' '));
}
else if(count.length==3 && count[1]!==count[2])
{
count.shift();
count.shift();
alert(count.join(' '));
}
else if(count.length>3)
{
count.shift();
alert(count.join(' '));
}
}

Not sure why it doesn't work beyond first time arround:eek:. Thanks again for any advice.

Edited by mike_2000_17: Fixed formatting

0

OK. I have it working better. I had to call the function 'counter()' twice, once at the begining of the onclick then at the end. It seems to work like a dream now. Hope I can pass the array.join in the Get httprequest!!!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.