I am trying to convert the output of the range from the input field to a Currency Format in Js. The Numbers are displaying correctly but I will like to convert it to Number Format on the output
const slider = document.getElementById("idc");
const value = document.getElementById("idk");
value.textContent = slider.value;
slider.oninput = function() {
value.textContent = this.value;
}
<input type="range" name="range" min="0" max="5000000" id="idc" step="1000" value="0">
<h4>$</h4>
<h4 id="idk">0</h4>
Does this work for you?
const slider = document.getElementById("idc");
const value = document.getElementById("idk");
value.textContent = slider.value;
slider.oninput = function() {
value.textContent = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(this.value);
}
<input type="range" name="range" min="0" max="5000000" id="idc" step="1000" value="0">
<h4>$</h4>
<h4 id="idk">0</h4>