javascript ใส่ , ที่หลักพัน

Post a reply

In an effort to prevent automatic submissions, we require that you complete the following challenge.
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review

Expand view Topic review: javascript ใส่ , ที่หลักพัน

javascript ใส่ , ที่หลักพัน

by jataz2 » 23/01/2019 5:45 pm

โค้ด html

Code: Select all

<input type="text" id="rate2"   onfocusout="thousandsSeparators(this.value);"></input>
โค้ด javascript

Code: Select all

function thousandsSeparators(str) {
                transactionAmount = str;

                var numParts = transactionAmount.toString().split(".");
                numParts[0] = numParts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");

                return numParts.join(".");
            catch (error)
            { }