...

View Full Version : Can't figure out the error-Please Help!



snakedevil1
08-04-2002, 10:59 PM
i know i already posted this, but this time its rewritten and a lot cleaner:
var wheretogo;
var whereis;
function GoTo(id)
{
whereis=document.all.selector.offsetLeft;
var whereisbyid;
switch(whereis)
{

case: 75
whereisbyid=1;

case: 150
whereisbyid=2;

case: 225
whereisbyid=3;

case: 300
whereisbyid=4;
}

if(whereisbyid>id)
{way="left"}

wheretogo=id*75;
var animation=setInterval("GoToPlace();",50);
}

function GoToPlace()
{

if(wheretogo != whereis)
{ whereis=whereis+1; } else {clearInterval(animation)}

}

I get a line 30 character 8 syntax error. I have no idea what it is, and line 30 is the Case: 75 line. i have no idea what is causing this error, any help would be appreciated.

adios
08-04-2002, 11:04 PM
Well - not that clean...

case 75 :
whereisbyid=1;

http://www.javascriptkit.com/javatutors/switch.shtml

snakedevil1
08-04-2002, 11:08 PM
oops :) thanx for pointing it out.

snakedevil1
08-04-2002, 11:09 PM
now whenever i click on it, i don't get any errors but it won't move! any help would be appreciated, heres teh code:
var animation;
var wheretogo;
var whereis;
function GoTo(id)
{
whereis=document.all.selector.offsetLeft;
var whereisbyid;
switch(whereis)
{

case 75:
whereisbyid=1;

case 150:
whereisbyid=2;

case 225:
whereisbyid=3;

case 300:
whereisbyid=4;
}

if(whereisbyid>id)
{way="left"}

wheretogo=id*75;
animation=setInterval("GoToPlace();",50);
}

function GoToPlace()
{

if(wheretogo != whereis)
{if(way="left"){whereis=whereis-1;} else {whereis=whereis+1;} } else {clearInterval(animation)}

}

glenngv
08-05-2002, 08:33 AM
you forgot to use break statement for each case.

case 75:
whereisbyid=1;
break;

case 150:
whereisbyid=2;
break;

case 225:
...

snakedevil1
08-05-2002, 08:37 PM
ok, thanx.
it still won't work though, the thing doesn't move.

snakedevil1
08-06-2002, 01:13 AM
any help? anybody?

glenngv
08-06-2002, 03:32 AM
i've fixed your code but i cannot see any code that makes it moved.

var animation;
var wheretogo;
var whereis;
function GoTo(id)
{
whereis=parseInt(document.all.selector.offsetLeft);
var whereisbyid=0;
switch(whereis)
{

case 75:
whereisbyid=1;break;

case 150:
whereisbyid=2;break;

case 225:
whereisbyid=3;break;

case 300:
whereisbyid=4;break;
}
alert("whereisbyid="+whereisbyid+"\nid="+id);
if(whereisbyid>id) way="left";
wheretogo=id*75;
animation=setInterval("GoToPlace();",50);
}


function GoToPlace()
{

if(wheretogo != whereis)
{
if(way=="left") whereis--;
else whereis++;
//where is the code that you want an object to move?
}
else clearInterval(animation)

}

snakedevil1
08-06-2002, 10:10 PM
the code is right there, i've put it in bold....

var animation;
var wheretogo;
var whereis;
function GoTo(id)
{
whereis=parseInt(document.all.selector.offsetLeft);
var whereisbyid=0;
switch(whereis)
{

case 75:
whereisbyid=1;break;

case 150:
whereisbyid=2;break;

case 225:
whereisbyid=3;break;

case 300:
whereisbyid=4;break;
}
alert("whereisbyid="+whereisbyid+"\nid="+id);
if(whereisbyid>id) way="left";
wheretogo=id*75;
animation=setInterval("GoToPlace();",50);
// starts the animation using 'setinterval', which calls a function every set number of seconds
}


function GoToPlace()
{

if(wheretogo != whereis)
{
if(way=="left") whereis--;
else whereis++;
// adds the objects position by 1
}
else clearInterval(animation)
// clearinterval stops the animation
}

glenngv
08-07-2002, 02:03 AM
yes i see you increment whereis variable to 1.
but where do you use this variable? if this is the object's position (left or top) then where do you set the position of the object, it must look something like this:

for IE:
document.all["objectID"].style.left=whereis; //or .top

or for NS6:
document.getElementById("objectID").style.left=whereis; //or .top

i supposed that code must be in GoToPlace() function

snakedevil1
08-08-2002, 02:50 AM
o ya, i forgot that! thanx A LOT!!!!! I cant thank you enough, thanx SO much :). problem is, its moving all the way to the right, past where it is supposed to stop! its pretty funny u can c what i mean by going to www.vip3r.com . any ideas on whats causing this?

glenngv
08-08-2002, 03:15 AM
in GoToPlace() function, you have to set the variable way to something else other than "left", i supposed it's "right".
you need also to make sure the condition if(wheretogo != whereis) will not be satisfied at some point in order to go to else part that will stop the animation.

snakedevil1
08-08-2002, 10:20 PM
still doesn't stop though
i fixed the way problem
i don't know what u mean by making sure. please help!

thanx a lot! :)
btw, the vip3r.com isn't updated, if u want i've included the page source for the page this is going to be on...

snakedevil1
08-08-2002, 10:24 PM
forgot to attach it!

snakedevil1
08-09-2002, 11:48 PM
so i guess nobody can help me?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum