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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    This makes no sense, please help!

    I am relatively new to JavaScript, and I am having serious problems over a JavaScript function.

    I have 2 x 2 dimensional arrays of data to display on the screen, each array being 18 x 18. The arrays and displaying them is working fine, I have 2 lots of X and Y variable (LocX1, LocY1, LocX2 and LocY2) which I use to reference the cells of the arrays.

    I have 2 similar (but not identical) functions to move around these arrays using links on the screen.

    Function 1 moves around the first array and is fine -

    Code:
    function MoveMapView(strDirection) {
        if (strDirection == "North") {
            LocY2 -= 1;
            if (LocY2 < 0){
                LocY2 = 0;
            }
        }
        if (strDirection == "East") {
            LocX2 += 1;
            if (LocX2 > 17){
                LocX2 = 17;
            }
        }
        if (strDirection == "South") {
            LocY2 += 1;
            if (LocY2 > 17){
                LocY2 = 17;
            }
        }
        if (strDirection == "West") {
            LocX2 -= 1;
            if (LocX2 < 0){
                LocX2 = 0;
            }
        }
        //Call the display functions
    ..
    ..
    }
    However function 2 (below) adds one to the end of LocY2 as though it was a string when you click the link for 'South'.

    Code:
    <!--  /* Style Definitions */  p.MsoNormal, li.MsoNormal, div.MsoNormal     {mso-style-parent:&quot;&quot;;     margin:0cm;     margin-bottom:.0001pt;     mso-pagination:widow-orphan;     font-size:12.0pt;     font-family:&quot;Times New Roman&quot;;     mso-fareast-font-family:&quot;Times New Roman&quot;;} @page Section1     {size:612.0pt 792.0pt;     margin:72.0pt 90.0pt 72.0pt 90.0pt;     mso-header-margin:36.0pt;     mso-footer-margin:36.0pt;     mso-paper-source:0;} div.Section1     {page:Section1;} --> function MoveSector(strDirection) {
          if (strDirection == "North") {
                LocY1 -= 1;
                if (LocY1 < 0){
                      LocY1 = 0;
                }
          }
          if (strDirection == "East") {
                LocX1 += 1;
                if (LocX1 > 17){
                      LocX1 = 17;
                }
          }
          if (strDirection == "South") {
                LocY1 += 1;
                if (LocY1 > 17){
                      LocY1 = 17;
                }
          }
          if (strDirection == "West") {
                LocX1 -= 1;
                if (LocX1 < 0){
                      LocX1 = 0;
                }
          }
          //Sava data to the cookie
          strText = "LocX1=" + LocX1;
          document.cookie = strText;
          strText = "LocY1=" + LocY1;
          document.cookie = strText;
          //Redirect
    location.replace('load.asp');
    
    }
    At the top of the page I have a routine to make sure that the numbers are numbers (as below).


    Code:
    // Make sure Location data is a number, may have been turned into a string
    //    LocX1= LocX1 + 0;
    //    LoxY1= LocY1 + 0;
    //    LocX2= LocX2 * 1;
    //    LoxY2= LocY2 * 1;
    
        LocX1= Number (LocX1);
        LoxY1= Number (LocY1);
        LocX2= Number (LocX2);
        LoxY2= Number (LocY2);
    As you can see, I have tried multiplying the variable by 1, adding zero and using the Number command. All other directions work fine and all links are identical, just passing a different 'direction' through an onClick.

    I know I am probably making a very simple and obvious mistake, but ANY help is appreciated. At this rate I will have no hair as well as no life!

    Thanks

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    You don't mention actually using any framework, so this probably would have bene better placed up in the main javascript forum. Would have received a good number of responses, too.

    Maybe the problem is in the function call itself. Check that area of the code and see what you're actually passing.
    Are you a Help Vampire?

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Cheers Tomws, this had done my head in I had miss read where I posted it ... will re-post in proper place


  •  

    Posting Permissions

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