I have a Javascript function that calculates a value and re-inserts the value into a <td>
while also injecting the value into a hidden <input>
.
This is my function:
$("input[name^='policies']:checkbox").change(function() {
var el = $(this);
if (el.is(":checked")) {
no_policies++;
}
if (el.is(":not(:checked)")) {
no_policies--;
}
subscription = no_policies*policy_cost;
first_payment = Math.ceil(subscription+no_policies*(policy_cost/days_month)*days_left).toFixed(2);
alert(first_payment);
$("td#first_payment").text("R "+first_payment);
$("input#first_payment_txt").val(first_payment);
$("td#subscription").text("R "+subscription.toFixed(2));
});
Everything works on IE8 up until this statement:
first_payment = Math.ceil(subscription+no_policies*(policy_cost/days_month)*days_left).toFixed(2);
I suspect IE8 is having trouble with Math.ceil
, is that true? Also, is there any other function/method I can use to circumvent this?
Thanks in advance.
I have a Javascript function that calculates a value and re-inserts the value into a <td>
while also injecting the value into a hidden <input>
.
This is my function:
$("input[name^='policies']:checkbox").change(function() {
var el = $(this);
if (el.is(":checked")) {
no_policies++;
}
if (el.is(":not(:checked)")) {
no_policies--;
}
subscription = no_policies*policy_cost;
first_payment = Math.ceil(subscription+no_policies*(policy_cost/days_month)*days_left).toFixed(2);
alert(first_payment);
$("td#first_payment").text("R "+first_payment);
$("input#first_payment_txt").val(first_payment);
$("td#subscription").text("R "+subscription.toFixed(2));
});
Everything works on IE8 up until this statement:
first_payment = Math.ceil(subscription+no_policies*(policy_cost/days_month)*days_left).toFixed(2);
I suspect IE8 is having trouble with Math.ceil
, is that true? Also, is there any other function/method I can use to circumvent this?
Thanks in advance.
Share Improve this question asked Mar 23, 2011 at 18:27 Anriëtte MyburghAnriëtte Myburgh 13.5k11 gold badges52 silver badges72 bronze badges 4- Are you sure the values are all numbers? Have you tried a clean script to test just Math.ceil with fixed values? – Adriano Varoli Piazza Commented Mar 23, 2011 at 18:30
- Uhm, no, I haven't, will try that quickly. Thanks. – Anriëtte Myburgh Commented Mar 23, 2011 at 18:32
- Thanks, that seems to do something, so obviously I need to initialize them somewhere. – Anriëtte Myburgh Commented Mar 23, 2011 at 18:36
- It's quite possible that the variables aren't initialized or are text, and then you'd have to cast them to numbers. – Adriano Varoli Piazza Commented Mar 23, 2011 at 20:49
3 Answers
Reset to default 5Answer is yes to both your questions:
Math.ceil()
Math.round()
Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards.
See also general table of Javascript patibility for different IE versions:
Seems like microsoft supports Math.ceil on all versions beginning from ie6 (msdn), maybe one of the variables use is undefined or you devide by 0 or one of the variables is not a number so the result cannot be ceiled/rounded.
IE8 actually has a fairly good debugger. I remend hitting F12 to open it, then going to the Script tab and selecting the Start Debugging button. This will let you set breakpoints along the script, letting it stop and wait for you to analyze variables as it executes at your own pace. As Adriano mentions in his ment, it's most likely an issue with one of your variables.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744399297a4572306.html
评论列表(0条)