'number expected' error in IE

Discussion in 'Javascript' started by David Cook, Jun 9, 2004.

  1. David Cook

    David Cook Guest

    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.dtd">
    <html>
    <head>
    <title>Whitewater Runs</title>
    <style type="text/css">
    table {table-collapse:collapse; 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:"elem1Value", elem2:"elem2Value",
    elem3:"elem3Value"};
    // (etc)


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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


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



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

    td = tr.insertCell(tr.cells.length);
    td.innerHTML = jsData.RiverName;

    td = tr.insertCell(tr.cells.length);
    td.setAttribute("align", "center");
    td.innerHTML = jsData.Location;

    td = tr.insertCell(tr.cells.length);
    td.setAttribute("align", "center");
    td.innerHTML = jsData.FlowType;

    td = tr.insertCell(tr.cells.length);
    td.setAttribute("align", "center");
    td.innerHTML = jsData.RunMiles;

    td = tr.insertCell(tr.cells.length);
    td.setAttribute("align", "center");
    td.innerHTML = jsData.State;

    td = tr.insertCell(tr.cells.length);
    td.setAttribute("align", "center");
    td.innerHTML = jsData.Latitude;

    td = tr.insertCell(tr.cells.length);
    td.setAttribute("align", "center");
    td.innerHTML = jsData.Longitude;
    }
    }

    // Remove existing table rows
    function clearTable(tbody) {
    while (tbody.rows.length > 0) {
    tbody.deleteRow(0);
    }
    }

    // Sorting function dispatcher (invoked by table column links)
    function sortTable(link) {
    switch (link.firstChild.nodeValue) {
    case "RiverName" :
    jsData.sort(sortByRiverName);
    break;
    case "Location" :
    jsData.sort(sortByLocation);
    break;
    case "FlowType" :
    jsData.sort(sortByFlowType);
    break;
    case "RunMiles" :
    jsData.sort(sortByRunMiles);
    break;
    case "State" :
    jsData.sort(sortByState);
    break;
    case "Latitude" :
    jsData.sort(sortByLatitude);
    break;
    case "Longitude" :
    jsData.sort(sortByLongitude);
    break;
    }
    drawTable("wwData")
    return false
    }

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

    </script>
    </head>

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



    <h2>Whitewater 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>
    David Cook, Jun 9, 2004
    #1
    1. Advertising

  2. 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

    > 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
    Vincent van Beveren, Jun 9, 2004
    #2
    1. Advertising

  3. "David Cook" <(who wants to know?)> writes:

    > The html file below gets intermittent errors 'error on page' ('number
    > expected')


    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("Androscoggin",
    "Errol Bridge to Pontook Rapid",
    "Dam",
    20.0,
    "NH",
    "N44/46.8'",
    "W71/07.8'"),
    new Run("Blue Hill Falls",
    "Blue Hill Falls",
    "Tide",
    0.0,
    "ME",
    "N44/23.6'",
    "W68/59.3'"),
    ...
    ];
    ---
    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 makePropertyComparator(property) {
    return function(a,b) {
    var ta = a[property].toLowerCase();
    var tb = b[property].toLowerCase();
    return (tb<ta)-(ta<tb); // shorter
    }
    }
    var sortByRiverName = makePropertyComparator("RiverName");
    var sortByLocation = makePropertyComparator("Location");
    var sortByFlowType = makePropertyComparator("FlowType");
    ....
    ---


    Good luck
    /L
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Jun 9, 2004
    #3
  4. JRS: In article <>, seen in
    news:comp.lang.javascript, Lasse Reichstein Nielsen <>
    posted at Wed, 9 Jun 2004 22:07:40 :
    >
    >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.


    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.demon.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)
    Dr John Stockton, Jun 10, 2004
    #4
  5. David Cook

    David Cook Guest

    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" <> wrote in message
    news:40c72368$0$6966$4all.nl...
    > 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
    >
    > > 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

    >
    David Cook, Jun 22, 2004
    #5
  6. David Cook

    Grant Wagner Guest

    <url:
    http://register.microsoft.com/conta...w.microsoft.com/&RU=http://www.microsoft.com/
    />

    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:

    > 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" <> wrote in message
    > news:40c72368$0$6966$4all.nl...
    > > 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
    > >
    > > > 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


    --
    | Grant Wagner <>

    * Client-side Javascript and Netscape 4 DOM Reference available at:
    *
    http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

    * Internet Explorer DOM Reference available at:
    *
    http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_entry.asp

    * 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-developer/upgrade_2.html
    Grant Wagner, Jun 22, 2004
    #6
  7. David Cook wrote:
    > The 'theory' sounds good. But, I changed all the lines to read:
    > return parseInt((a < b) ? -1 : ((a > b) ? 1 : 0));


    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.

    > This has got to be a known (but unfixed) bug in IE's javascript
    > support.


    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
    Thomas 'PointedEars' Lahn, Jun 29, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Ryan
    Replies:
    0
    Views:
    2,599
    Colin Ryan
    Sep 10, 2004
  2. Replies:
    1
    Views:
    689
    Joe Kesselman
    Sep 19, 2006
  3. Replies:
    13
    Views:
    12,897
    Kai-Uwe Bux
    Jan 22, 2007
  4. Jeff
    Replies:
    3
    Views:
    508
  5. Steve Chapel
    Replies:
    15
    Views:
    231
Loading...

Share This Page