最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Using an onblur event to send value to javascript function that will add .00 if it doesnt exist - Stack Overflow

programmeradmin1浏览0评论

From what I understand of onblur, it calls an event when you click out of the textbox. I have a text box where users an enter a value the want to pay.

<input id='Line Item' type="text" placeholder="Amount" name="AmountPaying" class="field m w-input" value="" >

From what I understand of onblur, it calls an event when you click out of the textbox. I have a text box where users an enter a value the want to pay.

<input id='Line Item' type="text" placeholder="Amount" name="AmountPaying" class="field m w-input" value="" >

If they enter a 1.1 and click out of the box, I want it to change the value to 1.10, Or 1 to 1.00

Share Improve this question asked Aug 3, 2016 at 21:49 jreed21jreed21 751 gold badge1 silver badge7 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 7

Something like this:

onblur="this.value=parseFloat(this.value).toFixed(2);"

<input placeholder="Amount" onblur="this.value=parseFloat(this.value).toFixed(2);" >

In your script file

document.querySelector('input[name="AmountPaying"]').addEventListener('blur', function() {
    this.value = parseFloat( this.value ).toFixed( 2 );
});

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论