Javascript in Mac: Number.toFixed challenge
Question posted by: glegipon
(Newbie)
on
February 7th, 2006 10:19 AM
As Tom Cahill would require, my challenge is (according to the "three
R's")
Reproducible: if run on OS 9.x, the monthly payment does not show up in
the text box:
Recognizable: I believe the Mac OS 9.x is not getting the temp_var
value returned to the var MP to show in the form. My hypothesis is
that the problems lies in this function:
- function round_2(Number)
-
{
-
var temp_var = (Number.toFixed(2))
-
return temp_var
-
}
-
Repairable:I believe I've located the error location, but this is my
2nd day coding Javascript, so I don't know if it's repairable. Is
there a fix to this? I heard if the Number.toFixed method isn't
available on the operating system, it is possible to write that method
as a function.
Here's my code:
Thanks for your help
|
|
April 16th, 2008 11:18 AM
# 2
|
Re: Javascript in Mac: Number.toFixed challenge
You can add toFixed if it doesn't exist. Either use a function or add it directly using prototype, e.g.
- if (!num.toFixed) {
-
Number.prototype.toFixed = function(precision) {
-
var num = (Math.round(this*Math.pow(10,precision))).toString ();
-
return num.substring(0,num.length-precision) + "." + num.substring(num.length-precision, num.length);
-
}
-
}
|
|
April 16th, 2008 12:01 PM
# 3
|
Re: Javascript in Mac: Number.toFixed challenge
and one more thing to mention: the problem is not the MAC ... it is the browser you would use with it that has to have an implementation of ECMA-Script ... and so the problem is the browser that is used with a specific OS ... and from that point of view the OS could be a problem when it limits the use of an up to date browser or the user who wants to use a specific browser that you have to support - but not the MAC itself :) ...
just this two cents from a MAC-user ... :)
kind regards
|
|
April 16th, 2008 12:57 PM
# 4
|
Re: Javascript in Mac: Number.toFixed challenge
Yes, of course, you're absolutely right!
Forgot to mention that... thanks!
It's probably either IE5 on the Mac or an old version of Safari that's the problem.
|
|
April 16th, 2008 01:52 PM
# 5
|
Re: Javascript in Mac: Number.toFixed challenge
While acoder's method is flawless, and gits remarks apt, I am not sure that toFixed is the problem. I didn't remember the 'onfilter ' event, which is the one calling the method, untitl I googled it,
Quote:
onfilter is a non existent event handler that web based email services such as Yahoo mail uses in place of actual event handlers inside emails that contain a JavaScript. It's a security precaution, to disable any malicious script from executing in the user's browser.
|
This doesn't mean he has the method toFixed, and anyone who doesn't can use acoder's replacement, but what event calls dosum?
|
|
April 17th, 2008 09:09 AM
# 6
|
Re: Javascript in Mac: Number.toFixed challenge
Good spot! Goes to show that three (sets of) eyes are better than one...
Quote:
what event calls dosum?
|
Probably via the CALCULATE link at the bottom, though onfiltered should probably be onchange.
Not the answer you were looking for? Post your question . . .
189,285 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).
|
|
|
Latest Articles: Read & Comment
Top Javascript / DHTML / Ajax Forum Contributors
|