Format textboxes
Does anyone have any idea as to format textboxes to automatically display characters for phone numbers such as dashes and parentheses without the user having to enter it themselves? This is the actual code I have but it's not working.
Any suggestions?
<script language="JavaScript">
function formatHPhone()
{
var value = document.Form1.txtHomePh.value;
var valueLen = document.Form1.txtHomePh.value.length;
//alert(value);
if(valueLen==0)
{
document.Form1.txtHomePh.value="(";
}
if(valueLen>3 && valueLen<5)
{
if(event.keyCode==8)
document.Form1.txtHomePh.value=document.Form1.txtH omePh.value.remove(valueLen-1,1);
else
document.Form1.txtHomePh.value=document.Form1.txtH omePh.value+")-";
}
if(valueLen>8 && valueLen<10)
{
if(event.keyCode==8)
document.Form1.txtHomePh.value=document.Form1.txtH omePh.value.remove(valueLen-1,1);
else
document.Form1.txtHomePh.value=document.Form1.txtH omePh.value+"-";
}
}
</script>
|