Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-17-2009, 08:19 PM   PM User | #1
bilbo.baggins
New to the CF scene

 
Join Date: Mar 2009
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
bilbo.baggins is an unknown quantity at this point
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
bilbo.baggins is offline   Reply With Quote
Old 03-17-2009, 09:46 PM   PM User | #2
tomws
Senior Coder

 
tomws's Avatar
 
Join Date: Nov 2007
Location: Arkansas
Posts: 2,644
Thanks: 29
Thanked 330 Times in 326 Posts
tomws will become famous soon enoughtomws will become famous soon enough
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?
tomws is offline   Reply With Quote
Old 03-18-2009, 12:36 AM   PM User | #3
bilbo.baggins
New to the CF scene

 
Join Date: Mar 2009
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
bilbo.baggins is an unknown quantity at this point
Cheers Tomws, this had done my head in I had miss read where I posted it ... will re-post in proper place
bilbo.baggins is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:36 AM.


Advertisement
Log in to turn off these ads.