user995691 user995691 - 1 year ago 397
Javascript Question

JQuery toFixed is not a function

I have this JavaScript code:

if($('#numlic').val() <= 10) {
$('#totalprice').text(23.10 * $('#numlic').val()).toFixed(2);

but it doesn't work and I get the "toFixed is not a function" error.
Can you help me with this?
Thanks in advance.

Answer Source

It's a simple typo:

if($('#numlic').val() <= 10) {
    $('#totalprice').text((23.10 * $('#numlic').val()).toFixed(2));

The toFixed function is an extension of a Number. You're trying to set the element $('#totalprice') .toFixed(2), when you want to set the result of "23.10 * $('#numlic').val()".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download