Friday, December 1, 2023
HomeSoftware DevelopmentEnter valueAsNumber

Enter valueAsNumber


Each every now and then I find out about a JavaScript property that I want I had identified about years earlier — valueAsNumber is one in all them. The valueAsNumber supplies the worth of an enter[type=number] as a Quantity sort, as an alternative of the normal string illustration whenever you get the worth:

/*
 Assuming an <enter sort="quantity" worth="1.234" />
*/

// BAD: Get the worth and convert the quantity
enter.worth // "1.234"
const numberValue = parseFloat(enter.worth, 10);

// GOOD: Use valueAsNumber
enter.valueAsNumber // 1.234

This property permits us to keep away from parseInt/parseFloat, however one gotcha with valueAsNumber is that it’ll return NaN if the enter is empty.

Thanks to Steve Sewell for making me conscious of valueAsNumber!

  • HTML5 Placeholder Styling with CSS

    Final week I confirmed you the way you possibly can fashion chosen textual content with CSS. I’ve looked for extra attention-grabbing CSS fashion properties and located one other: INPUT placeholder styling. Let me present you fashion placeholder textual content inside INPUTcomponents with some distinctive CSS code. The CSS Firefox…

  • Fading Links Using jQuery:  dwFadingLinks

    UPDATE: The jQuery web site was down at this time which brought on some points with my instance. I’ve made all the things native and now the instance works. Earlier this week, I posted a MooTools script that pale hyperlinks to and from a shade throughout the mouseover and mouseout occasions.


RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments