Reputation: 1667
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
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
$(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.
Hope this help you
Upvotes: 2