I am new to javascript, so this may seem like a trivial question. I am trying trying to write a javascript program that will insert dashes into a phone number, but I can't get my code to work. Nothing is happening when I use onkeyup
.
Am I doing something wrong? So far, it seems like only onfocus
is working for me.
function keyup() {
var mystring;
mystring.concat(document.getElementById('Phone').value, '-');
document.getElementById('Phone').setAttribute('value', mystring);
}
<input type="text" id="Phone" name="Phone" pattern="\d{3}[\-]\d{3}[\-]\d{4}" placeholder="###-###-####" onkeyup="keyup">
My editor has issues and is highlighting stuff. Is there an issue with single quotes double quotes? Are the returns in the lines alright? It appears ok when I view the source on Chrome version 66.