I am formatting the phone field. I get the value of the element and check to see if it 3 characters. The problem comes when the value ends with two zeros. The length of the var is off if it ends in two zeros.
Example:
120
value comes in at 3
1200
value also comes in at 3
//phone format
function updatephone(x) {
var phlen = document.getElementById("fphone").value;
if (phlen.length < 12) {
if (phlen.length == 3) {
document.getElementById('fphone').value=document.getElementById('fphone').value + -x;
}
else if (phlen.length == 7) {
document.getElementById('fphone').value=document.getElementById('fphone').value + -x;
}
else {
document.getElementById('fphone').value=document.getElementById('fphone').value + x;
}
}
}