1

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/

user3185936
  • 1,567
  • 6
  • 23
  • 44

1 Answers1

2

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

Jaykumar Patel
  • 26,836
  • 12
  • 74
  • 76