C
Cah Sableng
Hi all.
I am new member of this group.
I have a problem with currency formatter function I made. On onkeyup's
method of a textfield I add function below:
<snip>
function formatCurrency(elm) {
var str=elm.value;
var re = /(-?\d+)(\d{3})(,\d*)?/
var re1 = /\./g
str = str.replace(re1,'')
arr = str.split(',')
str = arr[0]
while (re.test(str))
str = str.replace(re, '$1.$2$3')
str += (arr.length > 1) ? (',' + arr[1]) : '';
elm.value = str
}
</snip>
It works as I expected, except that after the function finished its
execution the cursor moves to the end of the textfield. So if I want
to insert two or more characters, the rest of it goes to the end of
textfield.
How I determine the position of the cursor in the textfield before
executing the regex?
Sorry for the bad english I wrote.
TIA.
I am new member of this group.
I have a problem with currency formatter function I made. On onkeyup's
method of a textfield I add function below:
<snip>
function formatCurrency(elm) {
var str=elm.value;
var re = /(-?\d+)(\d{3})(,\d*)?/
var re1 = /\./g
str = str.replace(re1,'')
arr = str.split(',')
str = arr[0]
while (re.test(str))
str = str.replace(re, '$1.$2$3')
str += (arr.length > 1) ? (',' + arr[1]) : '';
elm.value = str
}
</snip>
It works as I expected, except that after the function finished its
execution the cursor moves to the end of the textfield. So if I want
to insert two or more characters, the rest of it goes to the end of
textfield.
How I determine the position of the cursor in the textfield before
executing the regex?
Sorry for the bad english I wrote.
TIA.