Filed under

Html

Entries from across the notebook, collected around this topic.

Explore this sectionAbout the author & following the notebook

The feed 4 entries

RSS feed
  1. Status

    Most developers when using HTML inputs with type="number" assume the input value …

    Cavallino-Treporti, Italy

    Most developers when using HTML inputs with type="number" assume the input value will be a number, and get confused when the value is a string instead. This is because the type=“number” actually tells the browser that the input is used for numbers and to provide a number input UI with included built-in validation to reject non-numerical entries.

    Now to get the number almost everyone will use the good old parser functions parseInt/parseFloat, like this:

    parseInt(input.value, 10);
    

    But, there is a less-known property called .valueAsNumber which allows us to avoid parseInt/parseFloat functions, for example:

    input.valueAsNumber
    

    How cool is that!