Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ajvanho's avatar
Level 14

return empty string or integer instead NaN

<input type="text" onchange="(function(el){el.value=parseFloat(el.value).toFixed(2);})(this)">

How to return empty string or empty value instead NaN after onchange event ?

0 likes
3 replies
jlrdw's avatar

If parsing, wouldn't you want a 0 rather. You could use a ternary to return 0 if the text is empty.

2 likes

Please or to participate in this conversation.