473,698 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Suddenly, a NaN error in Netscape

Hi!

I've modified a javascript order form calculation script that tallies
up the subtotal, shipping/handling, and total automatically.

I did some modifications and it still worked fine, even in Netscape,
but at some point the Shipping/Handling field has ceased to display
correctly in that browser, showing a Not A Number error. (In Safari it
looks fine, and it calculates correctly in all browsers I've tested it
with.)

http://wiseowlmultimedia.com/learnin...s_orderUS.html

I'm no java genius, just a copy-paste-and-tinker boy, so I've
basically got no clue what I messed up. My fine-tooth comb has turned
up no reason I can see why it broke. Can anyone help?

Thanks!
Adam

PS - It does act a bit peculiar in IE - I found I needed to click on
all the subtotal fields to make them show anything - but I suppose
that's just a java quirk of Explorer...
Jul 23 '05
17 1780
Michael Winter wrote:
<snip>
It seems that Netscape is correct; there are invalid characters
in the file. When I examined it with a binary editor, the
indentation is made with character code 160 (0xA0). I don't know
why, but either you inadvertantly inserted them, your editor did,
or your news reader did when you copied my post. Check the file
format your editor uses. Make sure it uses plain or ANSI text.

<snip>

Not a newsreader but Developersdex's web interface, and probably many
other web interfaces. Rather than doing the obvious thing and displaying
news messages in PRE tags to preserve the formatting inherent in the
original content, numerous web interfaces attempt to re-format posts as
HTML, padding indentation with &nbsp: and inserting <br> at the and of
lines. Obviously copying &nbsp; (0xA0) will transfer it literally into
some text editors (not unreasonably).

Developersdex used to be quite a reasonable web interface to Usenet but
they have gone down hill very fast recently. The writing was probably on
the wall the moment they decided to start spamming anyone who started a
new thread in a group they covered. But they also seem to have done
something to reduce the overall quality of their users. In the past
questions originating from Developersdex seemed, in the most part, to be
from developers with at least some understanding of what they were
doing. These days the average post originating on Developersdex is on a
par with a Forum4designers post.

Richard.
Jul 23 '05 #11
On Thu, 12 Aug 2004 16:08:56 +0100, Richard Cornford
<Ri*****@litote s.demon.co.uk> wrote:

[snip]
Not a newsreader but Developersdex's web interface, [...]
Obviously wasn't paying attention when I deleted the Developersdex
signature. :|

[snip]
Obviously copying &nbsp; (0xA0) will transfer it literally into
some text editors (not unreasonably).


I didn't realise that 0xA0 was &nbsp;. That would certainly explain it.

[snip]

Thanks,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail
Jul 23 '05 #12
Michael Winter wrote:
Richard Cornford wrote:

<snip>
Obviously copying &nbsp; (0xA0) will transfer it
literally into some text editors (not unreasonably).


I didn't realise that 0xA0 was &nbsp;. That would
certainly explain it.


Well, I have seen it before. Opera <= 6 won't process scripts that
contains 0xA0 (as whitespace) either. It is one of those problems where
positing code to Usenet just gets a lot of "it works in browser X for
me" responses and you can't see why it wouldn't work, or tell what is
going on until a URL is available.

Richard.
Jul 23 '05 #13
Invisible characters were indeed the source of the trouble!

Just as a test, I ran my faulty page through BBEdit's "Zap Gremlins"
filter
- and then, lo and behold, it worked. Brilliant!

(I had pasted the code from the website where I was viewing your reply
straight into GoLive, then uploaded. I won't do it that way again,
that's
for certain!)

I did need to modify the form to set all the quantity fields to "0", to
avoid
generating an error for each empty Quantity field. That being done, it
works like a charm.

Again, many many thanks for taking the time to work this whole thing
out for me. Besides enabling me to create the kind of page I envisioned,
the code will act as a studying point in improving my comprehension of
Javascript.

All the best!

Adam
http://www.adamabrams.com/

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #14
JRS: In article <opsclaiqbkx13k vk@atlantis>, dated Wed, 11 Aug 2004
22:37:48, seen in news:comp.lang. javascript, Michael Winter <M.Winter@bl
ueyonder.co.inv alid> posted :
In addition to the modified checks, I removed the rounding when
calculating the total. As 'q' will always be an integer, the value will
never go beyond two decimal places, making the rounding redundant.
I've not checked in your code; but you might consider whether the
observation that 10% of the lines given by
for (j=1 ; j<=100 ; j++) document.writel n(j*0.01, ' ', j, '<br>')
give more than two digits after the decimal point is pertinent.

ISTM that only if the factor, 0.01 above, is a multiple of 0.25 can one
rely on getting only two displayed digits. However, it seems that most
cases do give just two digits; therefore, a single test is likely to
pass.

Indeed, 3*0.1 and 0.1*3 both give me 0.3000000000000 0004 .


In article <opsck9qouox13k vk@atlantis>, dated Wed, 11 Aug 2004 22:21:04,
seen in news:comp.lang. javascript, Michael Winter <M.******@bluey onder.c
o.invalid> posted :
It should be:

/^\d+(\.\d{2})?$/


Fixed, thanks.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #15
On Thu, 12 Aug 2004 13:30:45 +0100, Dr John Stockton
<sp**@merlyn.de mon.co.uk> wrote:

[Example of inexactitude of floats in JavaScript]

I sometimes forget (when it matters, it seems) that floating-point
representations , in every form I should imagine, are approximates.

Although the errant bits probably won't interfere in even the extreme
cases, the rounding should remain, but in a better form. That includes
changing toCurrency() to take pennies:

function totalItem(i, e) {
/* Get references to the form controls. */
var oP = e['Item' + i + 'Price'],
oQ = e['Item' + i + 'Quantity'],
oT = e['Item' + i + 'Total'];
/* Get the values (convert them later). */
var p = oP.value, q = oQ.value, t;

/* Check that price is a well-formatted
* decimal. If not, quit. */
if(!/^(([1-9]\d*)|0)\.\d{2}$/.test(p)) {return;}
/* Convert price to number and multiply to work in
* pennies, reducing chance of rounding errors. */
p = Math.round(+p * 100);

/* Check that quantity is a positive
* integer. If not, quit. */
if(!/^([1-9]\d*)|0$/.test(q)) {return;}

/* Calculate total (in pennies). */
t = Math.round(p * q);

/* Convert the total to a formatted
* string and update the form. */
oT.value = toCurrency(t, '$', ',');
return t;
}

function totalOrder() {
var e = document.forms['orderform'].elements,
n = 40,
t = 0,
s;

/* Loop through items 1..n, computing the item
* total and adding it to the order total. */
for(var i = 1; i <= n; ++i) {
var x = totalItem(i, e);

/* Check for an error. */
if('undefined' == typeof x) {
alert('Item ' + i + ' contains an invalid value.\n' +
'Please correct it and try again.');
e['Item' + i + 'Quantity'].focus();
return;
}
t += x;
}
/* Less than $100, add 15%; $100 or more, add 10%.
* Note: totalItem() returns pennies. */
s = Math.round(t * ((t < 10000) ? 0.15 : 0.1));
/* Update the final totals. */
e['OrderTotal'].value = toCurrency(t, '$', ',');
e['SH'].value = toCurrency(s, '$', ',');
e['GrandTotal'].value = toCurrency(t + s, '$', ',');
}

/* n - Number to format (in pennies).
* c - Currency symbol to use.
* g - Grouping symbol.
*
* Outputs a number of the form cngnnngnnn.nn
*
* For example, toCurrency(1426 35.7, '£', ',') produces
* £1,426.36
*/
function toCurrency(n, c, g) {
var s = (0 > n) ? '-' : ''; n = Math.abs(n);
var m = String(Math.rou nd(n));
var j, i = '', f;

while(m.length < 3) {m = '0' + m;}
f = m.substring((j = m.length - 2));
while(j > 3) {
i = g + m.substring(j - 3, j) + i;
j -= 3;
}
i = m.substring(0, j) + i;
return s + c + i + '.' + f;
}

Hopefully, that's the end of the matter.

[snip]

Many thanks for these continued corrections,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail
Jul 23 '05 #16
On 12 Aug 2004 16:04:15 GMT, Adam Abrams <ad********@sha w.ca> wrote:

[snip]
I did need to modify the form to set all the quantity fields to"0", to
avoid generating an error for each empty Quantity field.That being done,
it works like a charm.
Hmm, yes. I overlooked that as well. I apologise.
Again, many many thanks for taking the time to work this wholething out
for me. Besides enabling me to create the kind of page Ienvisioned, the
code will act as a studying point in improving mycomprehension of
Javascript.


It's no problem.

If you want to improve your JavaScript, I don't think there are any places
better than this newsgroup. There are many knowledgeable people here and
they can teach you a lot.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail
Jul 23 '05 #17
JRS: In article <opscmtyocgx13k vk@atlantis>, dated Thu, 12 Aug 2004
18:34:39, seen in news:comp.lang. javascript, Michael Winter <M.Winter@bl
ueyonder.co.inv alid> posted :
I sometimes forget (when it matters, it seems) that floating-point
representation s, in every form I should imagine, are approximates.


Add to your imaginer a decimal float notation.

The mantissa of an IEEE Double is generally considered as binary, but
could equally well be considered as Hex.

Now instead of those Hex digits use decimal ones; there are (about?) 13
of them.

Any sum of money up to 10^13 pence can now be rendered exactly.

The signed exponent is 11 bits, which would support a range of +-400;
more than enough to keep Mr Brown happy, at least for a while.
ISTM that if CPUs had hardware instructions for true decimal types, both
integer and float (which nowadays would need only a little more
silicon), and software writers implemented such types, much time could
be saved.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4832
by: Mr. x | last post by:
Hello, I wrote a javascript, and when I open the html by the browser, I get the message : Error in page. It is about tousand lines, and I cannot figure out in a simple way, where is the line, that cause the error ? I see on other computers, a message like " ... do you wish to debug".
5
6373
by: Dan Tartakovsky | last post by:
Hi, folks. Does this error below look familiar to you? I'm trying to access function in one frame from the other frame. Error is received while working with Opera or Netscape (different errors). No problems are encountered with Microsoft IE - everything works fine. Any ideas about direction? // Opera error
2
2097
by: Simon | last post by:
I have recently set up a server certificate on a web site. Under certain conditions I need to change the color of a html span element. I do this using the following javascript function called from the onreset attribute of the form element. function removeWarningMsg() { if (isIE) { document.all.Warning.style.color = "<%=BACKGROUND_COLOUR%>";
1
1669
by: questionr | last post by:
There is a spell checker function which is written in VB Script. The function works well when tested seperately. But when the function is called from Java Script, the function shows an Error saying " A run time error has occured. Do you wish to debug? Line :0 , Object Expected". I just know that it is a Java Script error. Any suggestions on how to resolve this problem ? What could be the possible reasons for this error message?
6
6789
by: David Cook | last post by:
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...
8
3103
by: Dean Speir | last post by:
Hi... I've been referred to this Newsgroup by the W3C Markup Validator FAQ. I've been happily using this Validator <http://validator.w3.org> for the past 18 months with great success, but suddenly I cannot get it to "read" my HTML documents by the "Validate by File Upload" method. It keeps giving me the following message: Sorry, I am unable to validate this document
12
1743
by: melanieab | last post by:
Hi, I have a button that, when clicked, saves all the info entered. It worked fine until suddenly it didn't, and I have no idea why. I get the error An unhandled exception of type 'System.Xml.XmlException' occurred in system.xml.dll Additional information: System error. I found that this sometimes happens when there's some unrecognized character, so I even started with a new xml file, but it still won't work. It yells at me when I...
3
1398
by: Jack Fox | last post by:
I just upgraded my XP development machine to SP2, upgraded dotnet framework 1.1 to sp1, and applied every other outstanding security patch, and suddenly Server.Transfer in my asp.net website no longer works. I get: Invalid path for child request 'Browse.aspx?&p=4&q=14569:10.1.0.4;14581:3:6.0:7.3'. A virtual path is expected. What does it mean "virtual path is expected"? Isn't that what I'm giving it? And it worked yesterday! I didn't...
1
1518
by: teddysnips | last post by:
I recently had to rebuild an instance of SQL Server. When it was restarted, one of the client apps (ASP.NET) could not connect - the user could see the login screen, but it kept throwing exceptions. Turns out that the database had been restored with a different name, so the connection string (stored in web.config) was amended. At that point the system failed to display even the login screen - it failed with the error message shown at...
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9027
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7725
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.