Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > 'number expected' error in IE

Reply
Thread Tools

'number expected' error in IE

 
 
David Cook
Guest
Posts: n/a
 
      06-09-2004
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[i].RiverName;

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

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

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

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

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

td = tr.insertCell(tr.cells.length);
td.setAttribute("align", "center");
td.innerHTML = jsData[i].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>



 
Reply With Quote
 
 
 
 
Vincent van Beveren
Guest
Posts: n/a
 
      06-09-2004
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


 
Reply With Quote
 
 
 
 
Lasse Reichstein Nielsen
Guest
Posts: n/a
 
      06-09-2004
"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.'
 
Reply With Quote
 
Dr John Stockton
Guest
Posts: n/a
 
      06-10-2004
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] = {Datat=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)
 
Reply With Quote
 
David Cook
Guest
Posts: n/a
 
      06-22-2004

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

>



 
Reply With Quote
 
Grant Wagner
Guest
Posts: n/a
 
      06-22-2004
<url:
http://register.microsoft.com/contac...osoft%2Ecom%2F
/>

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$...
> > 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/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_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-deve...upgrade_2.html


 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      06-28-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0xffc Thread 0x228 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-30-2006 03:16 PM
Error connecting to SQLExpress 2005 locally (error: 26 - Error Locating Server/Instance Specified) hfk0 ASP .Net 2 03-27-2006 08:43 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 1 03-24-2006 04:20 PM
ERROR [HY000] [Microsoft][ODBC Microsoft Access Driver]General error Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x8fc Thread 0x934 DBC 0x437b94 Jet'. ERROR [IM006] [Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr bazzer ASP .Net 0 03-24-2006 02:22 PM
Error 500: ERROR: Cannot forward. Writer or Stream already obtained. Error JavaQueries Java 1 03-01-2005 06:30 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57