[thelist] JavaScript -- calculating & printing

Luther, Ron Ron.Luther at COMPAQ.com
Tue Apr 10 10:00:55 CDT 2001


Hi Lauri,


Some interesting stuff going on there alright.

(1) Yep - the metric calculation is "dominant" at the moment.  One of the
calculations needs to be. [I'd guess this is a consequence of working in a
'stateless' protocol -- you'd have to get pretty tricky with cookies or move
to server-side programming with session variables to have the page keep
track of whatever you changed last and process that correctly.  You might be
able to set up some "buffer" variables counting keystrokes in JavaScript in
each field - but that doesn't sound easy either.... Hmmmm ... maybe some
flags to identify the last field to have "Focus" might work?]  I threw in
the "reset" button as an easy way to let the user 'clear out' the fields and
go from feet to meters.  Lon's idea with the radio buttons might be the
answer here to let the user decide whether meters or feet should be
dominant. [Hint - you'd reverse the order they get calculated in - in the
function.... or use a second function with the order reversed.]

By the way - there is kind of another bug here now that you might not have
noticed:  http://www.tharapita.com/metric.htm 

The "onChange" gets confused eventually.  Use the top 2 boxes: Type a "10"
in meters, then a "10" in feet, "10" in meters, now a "10" in feet --- this
last change doesn't get converted!  Pretty Cool, eh?  Type another "10" in
meters and ... nothing happens.  [This is because it's an "onChange" event
and there is no change!! - Lon's "onBlur" probably wouldn't have this
problem.]


(2) The "precision" problem.  I did fool with this a bit more yesterday.  I
didn't see an easy fix - but I could have missed something.  I have some
ideas and will fool with it some more ... and might fix it, or might not.
"In my spare time" I will play with this - for fun ... unless I get
sidetracked by something else.  This is the tip of a very large iceberg -
the precision of arithmetic in computers has been an issue for a long time
... and will most likely continue to be for some time to come.  [You also
have JavaScript as a "typeless" language to contend with.]  The old
calculator that used to come with Windows had similar problems.  Many
spreadsheet programs from Lotus 1A* on have had this issue as well.  [Wait
until you have to explain to the CFO why the percentages in his presentation
don't sum to 100!]

I'm thinking about throwing in some additional variables and adding a
"format" function that uses [length] and [indexOf(".")] to decide how much
rounding to do ... {if you throw in an alert you will see that the "1" is
passed to the function - before the display changes to "0.999999999".}  Feel
free to give it a whirl first if you have more free time before I do.


Have Fun!

RonL.





More information about the thelist mailing list