Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New Coder
    Join Date
    Jun 2002
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can't figure out the error-Please Help!

    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.
    Last edited by snakedevil1; 08-04-2002 at 11:03 PM.
    Computers are simple for the complex mind, yet complex for the simple mind

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Well - not that clean...

    case 75 :
    whereisbyid=1;

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

  • #3
    New Coder
    Join Date
    Jun 2002
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    oops thanx for pointing it out.
    Computers are simple for the complex mind, yet complex for the simple mind

  • #4
    New Coder
    Join Date
    Jun 2002
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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)}

    }
    Last edited by snakedevil1; 08-04-2002 at 11:23 PM.
    Computers are simple for the complex mind, yet complex for the simple mind

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    you forgot to use break statement for each case.

    case 75:
    whereisbyid=1;
    break;

    case 150:
    whereisbyid=2;
    break;

    case 225:
    ...

  • #6
    New Coder
    Join Date
    Jun 2002
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, thanx.
    it still won't work though, the thing doesn't move.
    Computers are simple for the complex mind, yet complex for the simple mind

  • #7
    New Coder
    Join Date
    Jun 2002
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    any help? anybody?
    Computers are simple for the complex mind, yet complex for the simple mind

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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)

    }

  • #9
    New Coder
    Join Date
    Jun 2002
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    }
    Computers are simple for the complex mind, yet complex for the simple mind

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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

  • #11
    New Coder
    Join Date
    Jun 2002
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?
    Computers are simple for the complex mind, yet complex for the simple mind

  • #12
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,048
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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.

  • #13
    New Coder
    Join Date
    Jun 2002
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...
    Last edited by snakedevil1; 08-08-2002 at 10:24 PM.
    Computers are simple for the complex mind, yet complex for the simple mind

  • #14
    New Coder
    Join Date
    Jun 2002
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    forgot to attach it!
    Attached Files Attached Files
    Computers are simple for the complex mind, yet complex for the simple mind

  • #15
    New Coder
    Join Date
    Jun 2002
    Posts
    78
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so i guess nobody can help me?
    Computers are simple for the complex mind, yet complex for the simple mind


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •