Web Analytics Made Easy -
StatCounter breaking a fundamental law of mathematics - CodingForum

Announcement

Collapse
No announcement yet.

breaking a fundamental law of mathematics

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • breaking a fundamental law of mathematics

    Hi,

    Here's a script I'm working on that's giving me fits:

    ====================================

    function removeRow(num) {
    var frm = document.forms[0];
    var num = new Number(num);
    var yearsNum = new Number(frm.NumYears.value);
    var divNames = buildArray("DIV", /d\d\d\da/);
    var fromLen = divNames.length;
    writeFirstValues(fromLen);
    var seeNSNarray = getVisibleNSNs();
    var seeNSNnums = new Array();
    for(var x=0; x < (seeNSNarray.length); x++) {
    seeNSNnums[x] = new Number(seeNSNarray[x].id.slice(3));
    }
    ***alert(seeNSNnums[1]==5);
    ***alert(num==5);
    ***alert(seeNSNnums[1]==num);
    ***for(var y=0; y < (seeNSNnums.length); y++) {
    ***if(seeNSNnums[y] == num) {var valid=true; alert(true);}
    ***}
    ***if(!valid) {alert("Please enter the number of a row containing an NSN."); return false;}
    frm.NSN.value=(frm.NSN.value-1);
    removed = NSN_value.splice((num-1), yearsNum);
    removed = FY.splice((num-1), yearsNum);
    removed = TotalQty.splice((num-1), yearsNum);
    removed = MinQty.splice((num-1), yearsNum);
    removed = MaxQty.splice((num-1), yearsNum);
    removed = Centra.splice((num-1), yearsNum);
    removed = CgCode.splice((num-1), yearsNum);
    removed = RevLetter.splice((num-1), yearsNum);
    removed = AMRC.splice((num-1), yearsNum);
    removed = TobyBid.splice((num-1), yearsNum);
    writeTable();
    };

    ===========================

    The six lines where I've added *** are the problem lines here. Notice that I have three alert functions, testing whether a variable is equal to five, then whether a second variable is also equal to five, then finally whether the first variable and second variable are equal to each other. I then set a flag variable if the two variables are equal that I use to validate the function.

    When I pass five as my function parameter (num), the alert messages come back "true", "true", and "false". How can this be!? Both variable should be the same variable type (number), and I can't see anything else that would affect this. I am completely bamboozled...help!

    Sam

  • #2
    I wonder if things are getting confused with the double definition of "num" as both a function parameter and as an internal variable:

    &nbsp;&nbsp;var num = new Number(num);
    Having said that, I've probably told you more than I know.

    Comment


    • #3
      That's already close - drop the "new" keyword when you convert num to a number. Simply do

      num = Number(num);

      Curiously enough, in your special case it seems that the equality operator tests for equality in objects, not values. seeNSNnums[1] refers to a different object than num does.
      I have assumed that during a simple equality testing statement both operands were called upon their toString() method, but obviously, that isn't the case. It works also with

      alert(seeNSNnums[1].toString() == num.toString());

      and should return to you in both cases "true". Note that I tested in IE5.5, perhaps this is a browser issue.
      De gustibus non est disputandum.

      Comment


      • #4
        No browser issue -- I dropped the "new" from my Number statement and it worked perfectly with IE6 and NN6. Thanks!

        Comment

        Working...
        X