www.webdeveloper.com
Results 1 to 2 of 2

Thread: call method of a function question.

  1. #1
    Join Date
    Apr 2012
    Posts
    47

    call method of a function question.

    I need to modify the last statement in the item_add_click function so it calls the update_display function by using the call method of that function. In this case, you donít need to pass arguments because you donít need to change the object thatís used for the this parameter. Here is my code:

    Code:
    var invoice = [];
    
    var $ = function(id) { return document.getElementById(id); }
    
    var update_display = function () {
        $("item_list").value = get_item_list(invoice);
        $("subtotal").value = get_subtotal(invoice).toFixed(2);
        $("sales_tax").value = get_sales_tax(invoice).toFixed(2);
        $("total").value = get_total(invoice).toFixed(2);
    
        $("item_code").value = "";
        $("item_name").value = "";
        $("item_cost").value = "";
        $("item_qty").value = "1";
        
        $("item_code").focus();
    }    
    
    var item_add_click = function() {
        var item = [];
        item["item_code"] = $("item_code").value;
        item["item_name"] = $("item_name").value;
        item["item_cost"] = parseFloat($("item_cost").value);
        item["item_qty"]  = parseInt($("item_qty").value);
        
        if ( item["item_code"] == "" ) return;
        if ( item["item_name"] == "" ) return;
        if ( isNaN(item["item_cost"]) ) return;
        if ( isNaN(item["item_qty"] ) ) return;
    
        invoice.push(item);
        update_display();
    }
    
    window.onload = function () {
        $("item_add").onclick = item_add_click;
        $("item_code").focus();
    }
    any and all help is very much appreciated. Thanks.

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by Tullamore View Post
    I need to modify the last statement in the item_add_click function so it calls the update_display function by using the call method of that function
    What do you mean by "the method of a function"? There is no method defined there, and, anyway, methods can be defined as being properties of an object, or there is no object created there becuase you did not use that function as a constructor.

    Can you detail a little bit your aim, please? I confess I did not understand which, in fact, is your problem.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles