javascript - how to change the value of input box just for display in html 5 web page -
i have textfield in entering data want if user enter 1000 show 1,000 in textfield same value 1000 used in calculations further how solve if user enter 1000 display show 1,000 , if use in calcualtion same var shows 1000 calculating.
<html> <body> <input type="text" id="test" value="" /> </body> <script> var c=document.getelementbyid(test); </script> </html>
so if c user enter 1000 should dispaly 1,000 dispaly 1 , if user uses in script
var test=c
then test should show 1000
document.getelementbyid
returns either null
or reference unique element, in case input
element. input elements have attribute value
contains current value (as string).
so can use
var test = parseint(c.value, 10);
to current value. means if didn't use predefined value test
nan
.
however, evaluated once. in order change value you'll need add event listener, handles changes input:
// or c.onkeyup c.onchange = function(e){ /* ... */ }
Comments
Post a Comment