[html] Force decimal point instead of comma in HTML5 number input (client-side)

I have written a custom piece of code to do this

If you want to replace , with ., remove translate_decimals functions completely.

_x000D_
_x000D_
var input = document.querySelector('input[role="custom-number"]');_x000D_
var bincr = document.querySelector('button[role="increment"]');_x000D_
var bdecr = document.querySelector('button[role="decrement"]');_x000D_
_x000D_
function translate_decimals(side = 0)_x000D_
{_x000D_
 input.value = (side == ',' ? input.value.replace('.',',') : input.value.replace(',','.'));_x000D_
}_x000D_
translate_decimals(',');_x000D_
_x000D_
bincr.addEventListener('click', ()=>{_x000D_
 if (input.hasAttribute('max'))_x000D_
 {_x000D_
  if (input.value.substr(0,input.getAttribute('max').length) == input.getAttribute('max').substr(0,input.getAttribute('max').length))_x000D_
  {_x000D_
   return;_x000D_
  }_x000D_
  else_x000D_
  {_x000D_
   translate_decimals('.');_x000D_
   let temp = input.value;_x000D_
   input.value = "";_x000D_
   input.value = (input.hasAttribute('step') ? (parseFloat(temp) + parseFloat(input.getAttribute('step'))) : temp++);_x000D_
   translate_decimals(',');_x000D_
  }_x000D_
 }_x000D_
});_x000D_
_x000D_
bdecr.addEventListener('click', ()=>{_x000D_
 if (input.hasAttribute('min'))_x000D_
 {_x000D_
  if (input.value.substr(0,input.getAttribute('min').length) == input.getAttribute('min').substr(0,input.getAttribute('min').length))_x000D_
  {_x000D_
   return;_x000D_
  }_x000D_
  else_x000D_
  {_x000D_
   translate_decimals('.');_x000D_
   input.value = (input.hasAttribute('step') ? (input.value - input.getAttribute('step')) : input.value--);_x000D_
   translate_decimals(',');_x000D_
  }_x000D_
 }_x000D_
});
_x000D_
/* styling increment & decrement buttons */_x000D_
button[role="increment"],_x000D_
button[role="decrement"] {_x000D_
 width:32px;_x000D_
}
_x000D_
<input type="text" role="custom-number" step="0.01" min="0" max="0" lang="en" value="1.99">_x000D_
<button role="increment">+</button>_x000D_
<button role="decrement">-</button>
_x000D_
_x000D_
_x000D_

Examples related to html

Embed ruby within URL : Middleman Blog Please help me convert this script to a simple image slider Generating a list of pages (not posts) without the index file Why there is this "clear" class before footer? Is it possible to change the content HTML5 alert messages? Getting all files in directory with ajax DevTools failed to load SourceMap: Could not load content for chrome-extension How to set width of mat-table column in angular? How to open a link in new tab using angular? ERROR Error: Uncaught (in promise), Cannot match any routes. URL Segment

Examples related to google-chrome

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81 SameSite warning Chrome 77 What's the net::ERR_HTTP2_PROTOCOL_ERROR about? session not created: This version of ChromeDriver only supports Chrome version 74 error with ChromeDriver Chrome using Selenium Jupyter Notebook not saving: '_xsrf' argument missing from post How to fix 'Unchecked runtime.lastError: The message port closed before a response was received' chrome issue? Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser How to make audio autoplay on chrome How to handle "Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first." on Desktop with Chrome 66?

Examples related to input

Angular 4 - get input value React - clearing an input value after form submit Min and max value of input in angular4 application Disable Button in Angular 2 Angular2 - Input Field To Accept Only Numbers How to validate white spaces/empty spaces? [Angular 2] Can't bind to 'ngModel' since it isn't a known property of 'input' Mask for an Input to allow phone numbers? File upload from <input type="file"> Why does the html input with type "number" allow the letter 'e' to be entered in the field?

Examples related to numbers

how to display a javascript var in html body How to label scatterplot points by name? Allow 2 decimal places in <input type="number"> Why does the html input with type "number" allow the letter 'e' to be entered in the field? Explanation on Integer.MAX_VALUE and Integer.MIN_VALUE to find min and max value in an array Input type "number" won't resize C++ - how to find the length of an integer How to Generate a random number of fixed length using JavaScript? How do you check in python whether a string contains only numbers? Turn a single number into single digits Python

Examples related to decimal

Java and unlimited decimal places? What are the parameters for the number Pipe - Angular 2 Limit to 2 decimal places with a simple pipe C++ - Decimal to binary converting Using Math.round to round to one decimal place? String to decimal conversion: dot separation instead of comma Python: Remove division decimal Converting Decimal to Binary Java Check if decimal value is null Remove useless zero digits from decimals in PHP