0

Hi Guys i encounter Problem on my program which says that i have no method 'toFixed' what is the meaning or what to do to fix this?

Here is MY javascript

<script type="text/javascript">
    $(document).ready(function(){

        $("#datepicker").kendoDateTimePicker({
            format: "yyyy-MM-dd HH:mm:ss"

        });

        $("#supplier_list").kendoComboBox();
        $(".code_select").kendoComboBox();

        //automatic computation in rows
        $('[id^=qty],[id^=price],#tin_number').on('change',function() {

            var index = this.id.match(/\d+/)[0];
            var qty = parseInt($('#qty'+index).val());
            var price = parseFloat($('#price'+index).val());
            var disc = $("#discount").val();
            var total = 0;

            $('#total'+index).val((qty * price ? qty * price : 0).toFixed(2));

            var total = 0;
            $('[id^=total]').each(function(index){
                total+=parseFloat($(this).val()?$(this).val():0);
            });

            var totalAll = $('#sum_of_total').val(total.toFixed(2));


            var vatable = 0;
            var vatable_amt = 0;
            var totalVat = 0;
            var computeDisc = 0;

            if($("#tin_number").val().length != 0){
                vatable = total / 1.12;
                vatable_amt = vatable * 0.12;
                totalVat = vatable + vatable_amt;

            }else{
                totalVat = total;

            }

            $('#vatable').val(vatable.toFixed(2)); 
            $("#vatable_amount").val(vatable_amt.toFixed(2));
            var gtotal = $("#gtotal").val(totalVat.toFixed(2));
            $("#total_amt_due").val(gtotal.toFixed(2));

// Here is the line of error uncaught TypeError : Object[object object] has no method'toFixed'

});

        $("#discount").on('change',function(){
            var totalSales = $("#gtotal").val();
            var discountedAmt = $("#discount").val();
            var computeTotalDisc = totalSales - discountedAmt;
            $("#total_amt_due").val(computeTotalDisc.toFixed(2));
        });

        //AUTO ASSIGN TO SUPPLIER INFO
        $('#supplier_list').bind('change', function(){
            var var_add_category ='<?php echo site_url("purchaseorder_controller/supplier_details"); ?>';
            $.ajax({
                type:'POST',
                url: var_add_category,
                data:{ id: $(this).val() },
                dataType:'json',
                success:function(d){

                    var bankname = d['bankname'];
                    var bankbranch = d['bankbranch'];

                    $("[name=spaddress]").val(d['spaddr']);
                    $("[name=tin]").val(d['sptinno']);
                    $("[name=contactperson]").val(d['pricontactname']);
                    $("[name=contactnumber]").val(d['sptelno']);
                    $("[name=bank]").val(bankname + ' - ' + bankbranch);
                    $("[name=account_name]").val(d['bankacctname']);
                    $("[name=account_no]").val(d['bankacctno']);

                }
            });    
        });

        $("[id^=code]").on('change',function(){

            var index = this.id.match(/\d+/)[0];
            var validate = $('#code'+index).val();

            if(validate != ''){
                $("#qty"+index).removeAttr('readonly');
                $("#price"+index).removeAttr('readonly');
            }

        });

        $("[id^=code]").on('change',function(){

            var index = this.id.match(/\d+/)[0];
            var validate = $('#code'+index).val();

            if(validate == ''){
     $("#qty"+index).prop('readonly', true);
     $("#price"+index).prop('readonly', true);
 }

What to do pls help me guys thank you for the help in advance

4

3 回答 3

4

gtotal是一个 jQuery 对象,而不是一个数字?

var gtotal = $("#gtotal").val(totalVat.toFixed(2)); // returns jQuery object
$("#total_amt_due").val(gtotal.toFixed(2)); // that has no toFixed()

尝试:

var gtotal = totalVat.toFixed(2);

$("#gtotal, #total_amt_due").val(gtotal);
于 2013-09-11T15:36:05.670 回答
3

尝试这个:

var gtotal = +$("#gtotal").val(totalVat.toFixed(2)).val();

然后 gtotal 是数字。

于 2013-09-11T15:35:34.907 回答
0

此外,您无法计算已经 .toFixed() 的数字

所以你可以这样做

 $('#vatable').val(vatable.toFixed(2));   
 $("#vatable_amount").val(vatable_amt.toFixed(2));  
 var gTotal = totalVat;  
 $("#gtotal").val(totalVat.toFixed(2));  
 $("#total_amt_due").val(gtotal.toFixed(2));

但你不能这样做

var gTotal = totalVat.toFixed(2);  //pretend this equaled 1000.00
var total_amt_due = gTotal + 1.toFixed(2);// this would give you 1000.001.00 

或者

var total_amt_due = total_amt_due.toFixed(2);//this would give you the object no method toFixed error
于 2013-09-26T14:52:05.943 回答