dimanche 25 octobre 2015

Create a Cost calculator with javascript

I created a simple cost calulator that listens for onkeyup event and send the value and name of input. every name of input have its cost so it will be multiply the value and name to get the cost. also i have a total cost field. so my problem is if user enters a number like 5 then he/she change this to 4 but its not works fine and i know whats this for but i can't fix this.

my code is :

      var global=0;
  function costCalc(id,name){
    var input = document.getElementById(id);
    var inputValue = input.value;
    var inputName = input.getAttribute('name');
    var newSign= inputValue*inputName;
    global +=newSign;
    document.getElementById(name).textContent=""+newSign;
    document.getElementById('finalCost').textContent="جمع کل: "+global;
  }




Aucun commentaire:

Enregistrer un commentaire