javascript - Displaying number with thousand seperator -
I have the input field for the user for input number. This will be displayed in the span tags as user typing . And I want to format this number in a span tag with a thousand separator.
Currently, it only shows what is typing without a thousand separator:
Here is my simple code:
& Lt; Span id = "frm_price_preview" & gt; & Lt; / Span & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;
Answer no loop
function charPreview () {Var x = document.getElementById (" frm_price "). value; Document.getElementById ("frm_price_preview"). Internal html = numeral windom (x); } With the function number, commas (n) {var parts = n.toString (). Divided ("."); Return parts [0]. (/ = (? = (\ D {3}) + (?! \ D)) / g, ",") + (parts [1]? "." + Parts [1]: ""); } & lt; Forms & gt; Price: & lt; Input type = 'text' id = 'frm_price' onkeyup = "charPreview ()" & gt; & Amp; Nbsp & amp; Nbsp; & Lt; Span id = "frm_price_preview" & gt; This is where the user is shown typing & lt; / Span & gt; & Lt; / Form & gt; Also see which handles these types of things fairly well.
Comments
Post a Comment