I am trying to use java script to insert dashes into a html number field at every 4th
digit while entering.I did this in on-blur instead of on-key-press,on-key-up etc.But when I tried to change the function to on-key-press/on-key-up
events it is not giving the expected results.
This is the code which I used.
<html>
<head>
<script>
function addDashes(f)
{
f.value = f.value.slice(0,4)+"-"+f.value.slice(4,8)+"-"+f.value.slice(8,12);
}
</script>
</head>
<body>
Phone: <input type='text' name='phone' onblur='addDashes(this)' maxlength='12'><BR>
</body>
</html>
I am a beginner in 'JavaScript'. Where am I doing wrong?