开发者

Change JavaScript NaN Message to Something Else

开发者 https://www.devze.com 2023-02-08 08:48 出处:网络
I\'ve got an input[type=\"text\"] that throws up a NaN error until another box is filled. I know why the message is appearing, that\'s not a problem, it\'s correct. I开发者_JAVA技巧\'m just wondering

I've got an input[type="text"] that throws up a NaN error until another box is filled. I know why the message is appearing, that's not a problem, it's correct. I开发者_JAVA技巧'm just wondering if I can change 'NaN' to something more descriptive for the user.


if(isNaN(input.value)) {
    input2.value = '';//or a message of your choice
}


Test the value with isNaN(value) and if true then handle it however you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消