'number expected' error in IE

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Cook

    'number expected' error in IE

    The html file below gets intermittent errors 'error on page' ('number
    expected')
    when clicking on column-headings to sort. Yet, this same file works
    flawlessly
    in other browsers (i.e. Opera, Mozilla, Netscape, etc.).

    Can anyone suggest a fix/workaround?

    Cheers...

    Dave




    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/tr/xhtml1/DTD/xhtml1-transitional.dt d">
    <html>
    <head>
    <title>Whitewat er Runs</title>
    <style type="text/css">
    table {table-collapse:collap se; border-spacing:0;}
    td {border:2px groove black; padding:7px;
    background-color:lightgrey ;}
    th {border:2px groove black; padding:7px;
    background-color:lightblue ;}
    .ctr {text-align:center;}
    </style>
    <script type="text/javascript">
    // Table data -- an array of objects
    var jsData = new Array();
    // jsData[0] = {elem1:"elem1Va lue", elem2:"elem2Val ue",
    elem3:"elem3Val ue"};
    // (etc)


    jsData[0] =
    {
    RiverName : "Androscogg in",
    Location : "Errol Bridge to Pontook Rapid",
    FlowType : "Dam",
    RunMiles : 20.0,
    State : "NH",
    Latitude : "N44/46.8&#039;",
    Longitude : "W71/07.8&#039;"
    };


    jsData[1] =
    {
    RiverName : "Blue Hill Falls",
    Location : "Blue Hill Falls",
    FlowType : "Tide",
    RunMiles : 0.0,
    State : "ME",
    Latitude : "N44/23.6&#039;",
    Longitude : "W68/59.3&#039;"
    };


    jsData[2] =
    {
    RiverName : "Cohasset",
    Location : "Cohasset",
    FlowType : "Tide",
    RunMiles : 0.0,
    State : "MA",
    Latitude : "N42/14.5&#039;",
    Longitude : "W70/48.7&#039;"
    };


    jsData[3] =
    {
    RiverName : "Contoocook ",
    Location : "Hillsborou gh to Henniker",
    FlowType : "Rain",
    RunMiles : 2.2,
    State : "NH",
    Latitude : "N43/08.6&#039;",
    Longitude : "W71/52.2&#039;"
    };


    jsData[4] =
    {
    RiverName : "Dead(at low water levels)",
    Location : "Spencer Stream to the Forks",
    FlowType : "Dam",
    RunMiles : 20,
    State : "ME",
    Latitude : "N45/18.0&#039;",
    Longitude : "W70/13.0&#039;"
    };


    jsData[5] =
    {
    RiverName : "Dead(at high water levels)",
    Location : "Spencer Stream to the Forks",
    FlowType : "Dam",
    RunMiles : 20,
    State : "ME",
    Latitude : "N45/18.0&#039;",
    Longitude : "W70/13.0&#039;"
    };


    jsData[6] =
    {
    RiverName : "Deerfield (FifeBrook)",
    Location : "Fife Brook Dam to Zoar Gap",
    FlowType : "Dam",
    RunMiles : 4.8,
    State : "MA",
    Latitude : "N42/41.2&#039;",
    Longitude : "W73/06.8&#039;"
    };


    jsData[7] =
    {
    RiverName : "Deerfield (MonroeBrDryway )",
    Location : "Monroe Bridge to Dunbar Brook",
    FlowType : "Dam",
    RunMiles : 3.0,
    State : "MA",
    Latitude : "N42/42.0&#039;",
    Longitude : "W73/07.0&#039;"
    };


    jsData[8] =
    {
    RiverName : "Jenness Beach",
    Location : "Jenness Beach (Rye)",
    FlowType : "Surf",
    RunMiles : 0.0,
    State : "NH",
    Latitude : "N42/59.0&#039;",
    Longitude : "W70/45.8&#039;"
    };


    jsData[9] =
    {
    RiverName : "Kennebec",
    Location : "Harris Station Dam to the Forks",
    FlowType : "Dam",
    RunMiles : 11.0,
    State : "ME",
    Latitude : "N45/27.5&#039;",
    Longitude : "W69/51.7&#039;"
    };


    jsData[10] =
    {
    RiverName : "Magalloway ",
    Location : "Aziscohos Hydro to Wilson Mills",
    FlowType : "Dam",
    RunMiles : 1.75,
    State : "ME",
    Latitude : "N44/55.8&#039;",
    Longitude : "W70/59.0&#039;"
    };


    jsData[11] =
    {
    RiverName : "Merrimack" ,
    Location : "Arms Park (Manchester)",
    FlowType : "Dam",
    RunMiles : 0.5,
    State : "NH",
    Latitude : "N43/00.0&#039;",
    Longitude : "W71/26.7&#039;"
    };


    jsData[12] =
    {
    RiverName : "Merrimack" ,
    Location : "Heritage Trail(Bedford)" ,
    FlowType : "Dam",
    RunMiles : 0.6,
    State : "NH",
    Latitude : "N42/59.9&#039;",
    Longitude : "W71/26.7&#039;"
    };


    jsData[13] =
    {
    RiverName : "Ogunquit Beach",
    Location : "Ogunquit Beach",
    FlowType : "Surf",
    RunMiles : 0.0,
    State : "ME",
    Latitude : "N43/16.0&#039;",
    Longitude : "W70/35.3&#039;"
    };


    jsData[14] =
    {
    RiverName : "Pemigewasset(B ristol Gorge)",
    Location : "Ayers Island Dam to Coolidge Woods Rd",
    FlowType : "Dam",
    RunMiles : 1.0,
    State : "NH",
    Latitude : "N43/35.8&#039;",
    Longitude : "W71/43.1&#039;"
    };


    jsData[15] =
    {
    RiverName : "Piscataquo g",
    Location : "Goffstown to Pinardville",
    FlowType : "Dam",
    RunMiles : 2.0,
    State : "NH",
    Latitude : "N43/01.0&#039;",
    Longitude : "W71/34.1&#039;"
    };


    jsData[16] =
    {
    RiverName : "Quaboag",
    Location : "Warren to Route 67",
    FlowType : "Rain",
    RunMiles : 5.5,
    State : "MA",
    Latitude : "N42/12.7&#039;",
    Longitude : "W72/14.0&#039;"
    };


    jsData[17] =
    {
    RiverName : "Rapid",
    Location : "Middle Dam to Cedar Stump",
    FlowType : "Dam",
    RunMiles : 4.5,
    State : "ME",
    Latitude : "N44/46.0&#039;",
    Longitude : "W70/57.0&#039;"
    };


    jsData[18] =
    {
    RiverName : "Sheepscot Reversing Falls",
    Location : "5 miles northeast of Wiscasset",
    FlowType : "Tide",
    RunMiles : 0.0,
    State : "ME",
    Latitude : "N44/03.0&#039;",
    Longitude : "W69/37.0&#039;"
    };


    jsData[19] =
    {
    RiverName : "Souhegan",
    Location : "Greenville to Wilton",
    FlowType : "Rain",
    RunMiles : 3.5,
    State : "NH",
    Latitude : "N42/47.2&#039;",
    Longitude : "W71/48.2&#039;"
    };


    jsData[20] =
    {
    RiverName : "Millers (Upper)",
    Location : "South Royalston to Athol",
    FlowType : "Rain",
    RunMiles : 7.0,
    State : "MA",
    Latitude : "N42/37.8&#039;",
    Longitude : "W72/08.9&#039;"
    };


    jsData[21] =
    {
    RiverName : "West (upper)",
    Location : "Ball Mtn Dam to Jamaica St Park",
    FlowType : "Dam",
    RunMiles : 2.5,
    State : "VT",
    Latitude : "N43/07.6&#039;",
    Longitude : "W72/46.3&#039;"
    };


    jsData[22] =
    {
    RiverName : "West (lower)",
    Location : "Jamaica St Park to Townshend Res",
    FlowType : "Dam",
    RunMiles : 5.5,
    State : "VT",
    Latitude : "N43/06.3&#039;",
    Longitude : "W72/46.4&#039;"
    };


    jsData[23] =
    {
    RiverName : "White",
    Location : "N.Royalton to S.Royalton",
    FlowType : "Rain",
    RunMiles : 7.5,
    State : "VT",
    Latitude : "N43/49.3&#039;",
    Longitude : "W72/32.6&#039;"
    };


    jsData[24] =
    {
    RiverName : "Winnipesaukee" ,
    Location : "Franklin",
    FlowType : "Dam",
    RunMiles : 1.0,
    State : "NH",
    Latitude : "N43/26.6&#039;",
    Longitude : "W71/37.3&#039;"
    };



    // Draw table from 'jsData' array of objects
    function drawTable(tbody ) {
    var tr, td;
    tbody = document.getEle mentById(tbody) ;
    // remove existing rows, if any
    clearTable(tbod y);
    // loop through data source
    for (var i = 0; i < jsData.length; i++) {
    tr = tbody.insertRow (tbody.rows.len gth);

    td = tr.insertCell(t r.cells.length) ;
    td.innerHTML = jsData[i].RiverName;

    td = tr.insertCell(t r.cells.length) ;
    td.setAttribute ("align", "center");
    td.innerHTML = jsData[i].Location;

    td = tr.insertCell(t r.cells.length) ;
    td.setAttribute ("align", "center");
    td.innerHTML = jsData[i].FlowType;

    td = tr.insertCell(t r.cells.length) ;
    td.setAttribute ("align", "center");
    td.innerHTML = jsData[i].RunMiles;

    td = tr.insertCell(t r.cells.length) ;
    td.setAttribute ("align", "center");
    td.innerHTML = jsData[i].State;

    td = tr.insertCell(t r.cells.length) ;
    td.setAttribute ("align", "center");
    td.innerHTML = jsData[i].Latitude;

    td = tr.insertCell(t r.cells.length) ;
    td.setAttribute ("align", "center");
    td.innerHTML = jsData[i].Longitude;
    }
    }

    // Remove existing table rows
    function clearTable(tbod y) {
    while (tbody.rows.len gth > 0) {
    tbody.deleteRow (0);
    }
    }

    // Sorting function dispatcher (invoked by table column links)
    function sortTable(link) {
    switch (link.firstChil d.nodeValue) {
    case "RiverName" :
    jsData.sort(sor tByRiverName);
    break;
    case "Location" :
    jsData.sort(sor tByLocation);
    break;
    case "FlowType" :
    jsData.sort(sor tByFlowType);
    break;
    case "RunMiles" :
    jsData.sort(sor tByRunMiles);
    break;
    case "State" :
    jsData.sort(sor tByState);
    break;
    case "Latitude" :
    jsData.sort(sor tByLatitude);
    break;
    case "Longitude" :
    jsData.sort(sor tByLongitude);
    break;
    }
    drawTable("wwDa ta")
    return false
    }

    // Sorting functions (invoked by sortTable())
    function sortByRiverName (a, b) {
    a = a.RiverName.toL owerCase();
    b = b.RiverName.toL owerCase();
    return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    }
    function sortByLocation( a, b) {
    a = a.Location.toLo werCase();
    b = b.Location.toLo werCase();
    return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    }
    function sortByFlowType( a, b) {
    a = a.FlowType.toLo werCase();
    b = b.FlowType.toLo werCase();
    return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    }
    function sortByRunMiles( a, b) {
    return a.RunMiles - b.RunMiles;
    }
    function sortByState(a, b) {
    a = a.State.toLower Case();
    b = b.State.toLower Case();
    return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    }
    function sortByLatitude( a, b) {
    a = a.Latitude.toLo werCase();
    b = b.Latitude.toLo werCase();
    return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    }
    function sortByLongitude (a, b) {
    a = a.Longitude.toL owerCase();
    b = b.Longitude.toL owerCase();
    return ((a < b) ? -1 : ((a > b) ? 1 : 0));
    }

    </script>
    </head>

    <body onload="drawTab le('wwData')" bgcolor="white" >



    <h2>Whitewate r that I've run by kayak:</h2>
    <h4>(Note that client can now click on each column-heading to sort
    the data.)</h4>
    <h4>(Re-sorting happens on the client side...no further server hits
    are required!)</h4>
    <hr />

    <table id="myTable">
    <thead>
    <tr>
    <th><a href="#" title="Sort by RiverName"
    onclick="return sortTable(this) ">RiverName </a></th>
    <th><a href="#" title="Sort by Location"
    onclick="return sortTable(this) ">Location</a></th>
    <th><a href="#" title="Sort by FlowType"
    onclick="return sortTable(this) ">FlowType</a></th>
    <th><a href="#" title="Sort by RunMiles"
    onclick="return sortTable(this) ">RunMiles</a></th>
    <th><a href="#" title="Sort by State"
    onclick="return sortTable(this) ">State</a></th>
    <th><a href="#" title="Sort by Latitude"
    onclick="return sortTable(this) ">Latitude</a></th>
    <th><a href="#" title="Sort by Longitude"
    onclick="return sortTable(this) ">Longitude </a></th>
    </tr>
    </thead>
    <tbody id="wwData"></tbody>
    </table>

    </body>
    </html>



  • Vincent van Beveren

    #2
    Re: 'number expected' error in IE

    Hi David,

    Somehow it parse the return results for the sorting function wrongly
    and thinks its not a number, but a string. You could either take out
    all white spaces from the return values like this:

    return ((a < b) ?-1: ((a > b) ?1:0)); )

    But that wouldn't improve readability, so, you can also say it
    explicitly and simply changing

    return ((a < b) ? -1 : ((a > b) ? 1 : 0));

    into

    return parseInt((a < b) ? -1 : ((a > b) ? 1 : 0));

    should make things work.

    Good luck,
    Vincent
    [color=blue]
    > The html file below gets intermittent errors 'error on page' ('number
    > expected')
    > when clicking on column-headings to sort. Yet, this same file works
    > flawlessly
    > in other browsers (i.e. Opera, Mozilla, Netscape, etc.).
    >
    > Can anyone suggest a fix/workaround?
    >
    > Cheers...
    >
    > Dave[/color]

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: 'number expected' error in IE

      "David Cook" <(who wants to know?)> writes:
      [color=blue]
      > The html file below gets intermittent errors 'error on page' ('number
      > expected')[/color]

      Highly curious. This reduced example gives the same effect:
      ---
      var l = ["a","b"];
      var pa,pb;
      var sa,sb;
      function cmpx(a,b) {
      pa = a; pb = b;
      a = a.toLowerCase() ;
      b = b.toLowerCase() ;
      sa = a; sb = b;
      return ((a<b)? -1 : ((a>b)? 1 : 0));
      }
      try {
      for (var i=0; i<1000;i++) {
      l.sort(cmpx);
      }
      } catch (e) {
      alert(
      "after "+i+" rounds: "+ e.message + "\n" +
      "a = " + sa + "(" + typeof sa +"), was: " +
      pa + "(" + typeof pa + ")\n" +
      "b = " + sb + "(" + typeof sb +"), was: " +
      pb + "(" + typeof pb + ")\n");
      }
      ---

      It's definitly a bug.

      It seems toLowerCase fails, returning a value of unknown
      type. However, it only happens while being called from sort. Calling
      cmpx manually a million times doesn't fail.

      The problem also goes away if you rename the result, i.e., instead of
      a = a.toLowerCase() ;
      you write
      var ta = a.toLowerCase() ;
      Then "ta" is never foobar'ed like "a" is. (That's a workaround, by the way).


      I can see that you have a lot of repetetive code. There are ways to make
      that smaller.

      For the data, you can make a constructor function:
      ---
      function Run(riverName, location, flowType, runMiles,
      state, latitutde, longtitude) {
      this.RiverName = riverName;
      this.Location = location;
      this.FlowType = flowType;
      this.RunMiles = runMiles;
      this.State = state;
      this.Latitude = latitude;
      this.Longtitude = longtitude;
      }
      ---
      Then you can create the array in one go;
      ---
      var jsData = [
      new Run("Androscogg in",
      "Errol Bridge to Pontook Rapid",
      "Dam",
      20.0,
      "NH",
      "N44/46.8&#039;",
      "W71/07.8&#039;"),
      new Run("Blue Hill Falls",
      "Blue Hill Falls",
      "Tide",
      0.0,
      "ME",
      "N44/23.6&#039;",
      "W68/59.3&#039;"),
      ...
      ];
      ---
      This avoids the repetitions of "RiverName" etc.
      While it might not be as instantly readable, there are less risk of
      typos and less bytes to transfer.

      Also, the comparison functions are all very similar. You could
      use one function to generate all the comparison functions, avoiding
      duplicate code:
      ---
      function makePropertyCom parator(propert y) {
      return function(a,b) {
      var ta = a[property].toLowerCase();
      var tb = b[property].toLowerCase();
      return (tb<ta)-(ta<tb); // shorter
      }
      }
      var sortByRiverName = makePropertyCom parator("RiverN ame");
      var sortByLocation = makePropertyCom parator("Locati on");
      var sortByFlowType = makePropertyCom parator("FlowTy pe");
      ....
      ---


      Good luck
      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • Dr John Stockton

        #4
        Re: 'number expected' error in IE

        JRS: In article <7jugwl4j.fsf@h otpop.com>, seen in
        news:comp.lang. javascript, Lasse Reichstein Nielsen <lrn@hotpop.com >
        posted at Wed, 9 Jun 2004 22:07:40 :[color=blue]
        >
        >It seems toLowerCase fails, returning a value of unknown
        >type. However, it only happens while being called from sort. Calling
        >cmpx manually a million times doesn't fail.[/color]

        How about toUpperCase?

        Where the data being sorted is of significant size N, using toLowerCase
        in a comparison function is a program design error.

        The comparison function will be called, typically, more than o(N) times,
        such as o(N*ln(N)). Case conversion must involve iterating through the
        string and creating an object; it is not a negligible task.

        For N sufficiently (maybe not very) large, it will be better to use time
        o(N) to create the keys, and to use those keys in the comparison.

        Something like, starting with array A,
        var T = []
        for (J=0; J<N; J++) T[J] = {Data:(t=A[J]) ; Key:KeyFn(t)}
        then sort T with the comparison function comparing T[J].Key .

        Or just compare a simple key array but swap both Key & Data.

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
        Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
        Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
        Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

        Comment

        • David Cook

          #5
          Re: 'number expected' error in IE


          The 'theory' sounds good. But, I changed all the lines to read:
          return parseInt((a < b) ? -1 : ((a > b) ? 1 : 0));
          but I still get the 'number expected' error intermittently.

          This has got to be a known (but unfixed) bug in IE's javascript support.
          (I've seen other reports of getting this error but no one has found a
          solution.)

          If anyone knows a formal way of actually reporting this bug to Microsoft,
          I'd like to know how/where to send such a report.

          Cheers...

          Dave




          "Vincent van Beveren" <vincent@provid ent.remove.this .nl> wrote in message
          news:40c72368$0 $6966$e4fe514c@ news.xs4all.nl. ..[color=blue]
          > Hi David,
          >
          > Somehow it parse the return results for the sorting function wrongly
          > and thinks its not a number, but a string. You could either take out
          > all white spaces from the return values like this:
          >
          > return ((a < b) ?-1: ((a > b) ?1:0)); )
          >
          > But that wouldn't improve readability, so, you can also say it
          > explicitly and simply changing
          >
          > return ((a < b) ? -1 : ((a > b) ? 1 : 0));
          >
          > into
          >
          > return parseInt((a < b) ? -1 : ((a > b) ? 1 : 0));
          >
          > should make things work.
          >
          > Good luck,
          > Vincent
          >[color=green]
          > > The html file below gets intermittent errors 'error on page' ('number
          > > expected')
          > > when clicking on column-headings to sort. Yet, this same file works
          > > flawlessly
          > > in other browsers (i.e. Opera, Mozilla, Netscape, etc.).
          > >
          > > Can anyone suggest a fix/workaround?
          > >
          > > Cheers...
          > >
          > > Dave[/color]
          >[/color]


          Comment

          • Grant Wagner

            #6
            Re: 'number expected' error in IE

            <url:

            />

            Under:

            "Product Support"

            Click on:

            "Contact technical support, ask a product question, report a product bug or
            send comments about technical support. "

            When I sent a bug report on Internet Explorer I actually received a response
            from a human indicating it had been forwarded to the appropriate development
            team for review.

            They'll take you more seriously if you include as many details as you can and
            maybe provide a stripped-down sample page that demonstrates the behavior.

            David Cook wrote:
            [color=blue]
            > The 'theory' sounds good. But, I changed all the lines to read:
            > return parseInt((a < b) ? -1 : ((a > b) ? 1 : 0));
            > but I still get the 'number expected' error intermittently.
            >
            > This has got to be a known (but unfixed) bug in IE's javascript support.
            > (I've seen other reports of getting this error but no one has found a
            > solution.)
            >
            > If anyone knows a formal way of actually reporting this bug to Microsoft,
            > I'd like to know how/where to send such a report.
            >
            > Cheers...
            >
            > Dave
            >
            > "Vincent van Beveren" <vincent@provid ent.remove.this .nl> wrote in message
            > news:40c72368$0 $6966$e4fe514c@ news.xs4all.nl. ..[color=green]
            > > Hi David,
            > >
            > > Somehow it parse the return results for the sorting function wrongly
            > > and thinks its not a number, but a string. You could either take out
            > > all white spaces from the return values like this:
            > >
            > > return ((a < b) ?-1: ((a > b) ?1:0)); )
            > >
            > > But that wouldn't improve readability, so, you can also say it
            > > explicitly and simply changing
            > >
            > > return ((a < b) ? -1 : ((a > b) ? 1 : 0));
            > >
            > > into
            > >
            > > return parseInt((a < b) ? -1 : ((a > b) ? 1 : 0));
            > >
            > > should make things work.
            > >
            > > Good luck,
            > > Vincent
            > >[color=darkred]
            > > > The html file below gets intermittent errors 'error on page' ('number
            > > > expected')
            > > > when clicking on column-headings to sort. Yet, this same file works
            > > > flawlessly
            > > > in other browsers (i.e. Opera, Mozilla, Netscape, etc.).
            > > >
            > > > Can anyone suggest a fix/workaround?
            > > >
            > > > Cheers...
            > > >
            > > > Dave[/color][/color][/color]

            --
            | Grant Wagner <gwagner@agrico reunited.com>

            * Client-side Javascript and Netscape 4 DOM Reference available at:
            *


            * Internet Explorer DOM Reference available at:
            *
            Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


            * Netscape 6/7 DOM Reference available at:
            * http://www.mozilla.org/docs/dom/domref/
            * Tips for upgrading JavaScript for Netscape 7 / Mozilla
            * http://www.mozilla.org/docs/web-deve...upgrade_2.html


            Comment

            • Thomas 'PointedEars' Lahn

              #7
              Re: 'number expected' error in IE

              David Cook wrote:[color=blue]
              > The 'theory' sounds good. But, I changed all the lines to read:
              > return parseInt((a < b) ? -1 : ((a > b) ? 1 : 0));[/color]

              This can be simplified to

              return (a < b ? -1 : (a > b ? 1 : 0));

              Boolean expressions seldom need to be in parantheses and as the result
              of the evaluation of the two nested ternary operations is always an
              integer value (i.e. the fractional part of the floating-point number
              is 0), it really does not make sense to apply parseInt() to it.
              [color=blue]
              > This has got to be a known (but unfixed) bug in IE's javascript
              > support.[/color]

              IE does not support JavaScript, it supports JScript, Microsoft's
              ECMAScript implementation. But even if you used the above it
              is highly unlikely that it is this line which triggers the error.


              PointedEars

              Comment

              Working...