No. | Title |
---|---|
1 | Code Example 1 |
2 | Code Example 2 |
3 | Conclusion |
<input type="text" id="numberInput" oninput="autoAddSeparator(this)">
<script>
function autoAddSeparator(input) {
const value = input.value.replace(/,/g, ''); // Remove existing separators
input.value = Number(value).toLocaleString();
}
</script>
<select id="numberSelect" onchange="autoAddSeparatorToSelect(this)">
<option value="1000">1,000</option>
<option value="10000">10,000</option>
<option value="100000">100,000</option>
</select>
<script>
function autoAddSeparatorToSelect(select) {
const selectedOption = select.options[select.selectedIndex];
const value = selectedOption.value.replace(/,/g, ''); // Remove existing separators
selectedOption.text = Number(value).toLocaleString();
}
</script>