Click here to Skip to main content
15,888,238 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

i want to shift cursor after decimal point automatically if i enter one value.

for ex, 0.00 is the defalut value in textbox and if i enter one value into textbox cursor automaticallly shifed to after . point in textbox,this is my actual requirement.

What I have tried:

<script type="text/javascript">
        function AddComma(text) {
            switch (text.value.length) {
                case 1:
                    document.getElementById("txtNumber").value = "0.0" + text.value;
                    break;
                default:
                    var data = text.value.replace(".", "");
                    var first = data.substring(0, (data.length - 2));
                    var second = data.substring(data.length - 2);
                    var temp = Math.abs(first) + "." + second;
                    document.getElementById("txtNumber").value = temp;
            }
        }
    </script>


<input id="txtNumber" type="text" name="name" onkeyup="AddComma(this);" />
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900