473,231 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Javascript in Mac: Number.toFixed challenge

View Poll Results: Macs and javascript: to be or not to be, that is the question.
A match made in heaven, like summer & ice cream! 0 0%
Like McDonalds with healthy food, Mac's not there yet...but they are trying. 1 100.00%
Umm, something's wrong,...and I don't think they're trying. 0 0%
What's Mac got to do...(i said) got to do with it!?... 0 0%
Voters: 1. You may not vote on this poll

As Tom Cahill would require, my challenge is (according to the "three

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:

Expand|Select|Wrap|Line Numbers
  1.      function round_2(Number) 
  2.     {
  3.     var temp_var = (Number.toFixed(2))
  4.     return temp_var
  5.     }
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:

Expand|Select|Wrap|Line Numbers
  2. <HTML><HEAD><TITLE>Simple Mortgage Calculator</TITLE>
  3. <script language="JavaScript"> 
  4. function round_2(Number)
  5. {
  6. var temp_var = (Number.toFixed(2))
  7. return temp_var
  8. }
  10. function find_payment(A, B, C)
  11. {
  12. var temp_var = (A * B) / (1 - Math.pow(1 + B, -C))
  13. return temp_var
  14. }
  16. function dosum()
  17. {
  18. if(document.temps.PP.value>0)
  19. {
  20. if((document.temps.DP.value / document.temps.PP.value) <=0)
  21. {document.temps.DP.value=document.temps.PP.value/10}
  22. else if((document.temps.DP.value/document.temps.PP.value)<.1)
  23. {
  24. alert("A 10% Miminimum Down Payment Is Required.")
  25. document.temps.DP.value=document.temps.PP.value/10
  26. }
  27. else if((document.temps.DP.value/document.temps.PP.value)>=1)
  28. {
  29. alert("Come on. If you pay for the property in full at time of
  30. purchase, you won't need a loan. Why are you looking at terms? If you
  31. are going to pay in full, call me at (800) 760-3001 and I'll give you a
  32. 5% discount on the purchase of any property on our inventory.")
  33. document.temps.DP.value=document.temps.PP.value/10
  34. }
  35. else
  36. {document.temps.DP.value=document.temps.DP.value}
  38. if(document.temps.YR.value<=0)
  39. {document.temps.YR.value=15}
  40. else if(document.temps.YR.value>30)
  41. {
  42. alert("30 Year Is The Maximum Repayment Period.")
  43. document.temps.YR.value=30
  44. }
  45. else
  46. {document.temps.YR.value=document.temps.YR.value}
  48. document.temps.LA.value=document.temps.PP.value-document.temps.DP.value
  49. if((document.temps.DP.value/document.temps.PP.value)<.2)
  50. {document.temps.IR.value=.09}
  51. else if((document.temps.DP.value/document.temps.PP.value)<.3)
  52. {document.temps.IR.value=.085}
  53. else
  54. {document.temps.IR.value=.08}
  55. var MP = document.temps.MP.value
  56. var LA = document.temps.LA.value
  57. var IR = document.temps.IR.value
  58. var YR = document.temps.YR.value
  59. MP=find_payment(LA,IR/12,YR*12)
  61. document.temps.AT.value=(document.temps.PP.value*.0125)
  63. document.temps.MP.value=round_2(MP)
  64. }
  65. else
  66. {alert("Please Enter A Purchase Price")}
  67. }
  68. function clearboxes()
  69. {
  70. document.temps.PP.value = "";
  71. document.temps.DP.value = "";
  72. document.temps.LA.value = "";
  73. document.temps.YR.value = "";
  74. document.temps.IR.value = "";
  75. document.temps.MP.value = "";
  76. document.temps.AT.value = "";
  77. }
  78. // -->
  79. </script>
  80. </HEAD><b>Simple Mortgage Calculator</b><br>
  81. <br>
  82. <form name="temps">
  83. Loan Details...<br><br>
  84. <u>variable price</u>
  85. <br>Purchase Price:<input NAME="PP" onfiltered="dosum()" tabindex="1"
  86. size=15 style="font-size:9pt;">
  87. <hr width=95%><br><br>
  88. <u>terms are flexible</u>
  89. <br>Down Payment:<input NAME="DP" onfiltered="dosum()" tabindex="1"
  90. size=15 style="font-size:9pt;">
  91. <br>Repayment Period: (Years)<input NAME="YR" onfiltered="dosum()"
  92. tabindex="2" size=15 style="font-size:9pt;">
  93. <br>
  94. <br>
  95. Results...<br><br>
  96. <u>fixed numbers</u>
  97. <br>Monthly Payment:<input size=13 NAME="MP" style="font-size:9pt;"
  98. tabindex="8">
  99. <br>Loan Amount:<input NAME="LA" onfiltered="dosum()" tabindex="1"
  100. size=15 style="font-size:9pt;">
  101. <br>Interest Rate:<input size=15 style="font-size:9pt;" NAME="IR"
  102. "onfiltered="dosum()" tabindex="3">
  103. <br>Annual County Tax:<input size=13 NAME="AT" style="font-size:9pt;"
  104. tabindex="11">
  105. <br>
  107. <br><br><blockquote><a href="javascript:clearboxes()" width=58
  108. height=16 border=0>Clear</a>
  109. <br><br><a href="javascript:dosum()" width=100 height=16
  110. border=0>CALCULATE</a>
  111. </blockquote>
  112. <div align=center><font size=1>Calculations made by this tool are
  113. believed to be accurate but are not guaranteed.</font></div>
  114. </BODY></HTML>
Thanks for your help
Feb 7 '06 #1
5 6804
16,027 Expert Mod 8TB
You can add toFixed if it doesn't exist. Either use a function or add it directly using prototype, e.g.
Expand|Select|Wrap|Line Numbers
  1. if (!num.toFixed) {
  2.     Number.prototype.toFixed = function(precision) {
  3.         var num = (Math.round(this*Math.pow(10,precision))).toString();
  4.         return num.substring(0,num.length-precision) + "." + num.substring(num.length-precision, num.length);
  5.     }
  6. }
Apr 16 '08 #2
5,390 Expert Mod 4TB
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
Apr 16 '08 #3
16,027 Expert Mod 8TB
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.
Apr 16 '08 #4
428 256MB
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,

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?
Apr 16 '08 #5
16,027 Expert Mod 8TB
Good spot! Goes to show that three (sets of) eyes are better than one...
what event calls dosum?
Probably via the CALCULATE link at the bottom, though onfiltered should probably be onchange.
Apr 17 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Tom Cahill | last post by:
The following code will work perfectly on a PC browser, IE or Netscape. However on a Mac browser (IE, Netscape, or Safari) it does not. I have tried it on OSX and OS9. ANy help anyone can offer...
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...

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.