SetAttribute not working ( noobie )

Hello !

I´m new to the forums, so sorry if this is not the right place to ask for this.
I´m something like a “begginer” at javascript, and I dont know why, one function that I used on IE, doest work on Chrome. After the 9th digit is pressed, the input box stops working properly. On Chrome´s Developer Tools, it doesn´t throw me any errors. So I ask for help of the community to solve this probem. Thankyou in advance !

This is the HTML Code :

response.write “”

Function formataTelefone(e)
{
var tecla=(window.event)?event.keyCode:e.which;
var TxtTelefone = document.getElementById(“telefone”);
var vr = TxtTelefone.value;
var size = vr.length;

var TxtTamanho = document.getElementById(“TxtTamanho”);
TxtTamanho.setAttribute(“value”,size);
var TxtTecla = document.getElementById(“TxtTecla”);
TxtTecla.setAttribute(“value”,tecla);

if (tecla > 47 && tecla < 58)
{
if (size == 0 )
{
e.preventDefault();
e.stopImmediatePropagation();
vr = “(” + String.fromCharCode(tecla) ;
TxtTelefone.setAttribute(“value”,vr);
TxtTelefone.selectionStart = TxtTelefone.selectionEnd = TxtTelefone.value.length;
}

 if  (size == 2 )
 {
    e.preventDefault();
    e.stopImmediatePropagation();
    vr = vr + String.fromCharCode(tecla) ;
    vr = vr + ") ";
    TxtTelefone.setAttribute("value",vr);
    TxtTelefone.selectionStart = TxtTelefone.selectionEnd = TxtTelefone.value.length;
 }
 if ( (size == 9) )
 {
    e.preventDefault();
    e.stopImmediatePropagation();
    vr = vr + "-" + String.fromCharCode(tecla) ;
    TxtTelefone.setAttribute("value",vr);
    TxtTelefone.selectionStart = TxtTelefone.selectionEnd = TxtTelefone.value.length;
 }
 return true;

}
}