Display values with thousand separator with comma "," in data entry

Dear community,

I am not sure about values with thousand seperator in DHIS2, is it possible to do it with “,” . We need to customize in form ? Thanks in advance.

@hengkiry

If you are using custom data entry forms (HTML forms), you could:

  • Add JavaScript formatting to show 1,000 while typing.
  • Strip the commas before saving the value to DHIS2.

Add this script at the bottom of your custom form HTML

function formatNumber(input) {
// Remove existing commas
let value = input.value.replace(/,/g, ‘’);
// Check if it is a number
if (!isNaN(value) && value !== ‘’) {
// Add thousand separators
input.value = Number(value).toLocaleString(‘en-US’);
}
}
function removeCommas(input) {
input.value = input.value.replace(/,/g, ‘’);
}

Attach the functions to the input field:

input type=“text”
onkeyup=“formatNumber(this)”
onchange=“removeCommas(this)”

This keeps the stored value numeric (1000) while letting users see 1,000.

I’m sure you can do it :clap:

1 Like

Many thanks @HanyAly I will try and get you back the result