user3185936
user3185936

Reputation: 1667

Addition of two forms in the third form

Working on javascript to (+) from two forms and show it on the third one, but having a issue with that I want it to round the decimal to 2 as ,XX. And result is now showing in dot (.), how can I change it to show in comma ? It only let user write decimal values in dot, how can I change it to comma?

Jsfiddle: http://jsfiddle.net/eYj8B/4/

Upvotes: 1

Views: 93

Answers (1)

Jaykumar Patel
Jaykumar Patel

Reputation: 27614

You are missing semi colon (;) end of var inputs. and value.toString().replace('.', ',') to output value replace dot (.) to comma (,).

Check this demo jsFiddle

jQuery

$(function() {
  var inputs = $('input[name="M_Fritt_Klor"],input[name="M_Total_Klor"]');
      output = $('input[name="M_Bundet_Klor"]');
    function parse(value) {
        return parseFloat(value.replace(',','.'));
    }
  inputs.keyup(function() {
      var value = parse(inputs[0].value)+parse(inputs[1].value);
      if (!isNaN(value)) {
          output.val(value.toString().replace('.', ','));
      }
  });
});

Yes, its work comma instead of dot.

Result

enter image description here

Hope this help you

Upvotes: 2

Related Questions