I have a textbox control that is used to receive a CPF or CNPJ and the same and made a check to accept only numbers. The label that stands in front of the textbox only appears when the page is saved and shows the CPF or CNPJ formatted with mascarra. I wanted to know when the page has already been saved and the user modify the CPF or CNPJ to change the value of the label when the textbox loses focus. I am already using Usage: onKeyUp, OnKeyPress and onBlur, are used in the 3 to avoid Ctrl + V, Paste Mouse or typing, they are all done in javascript. In the onblur I can call 2 function and how to get the value of the textbox and play in the label by javascript?
Thank you for being able to help me.
/*
Utilização:
onKeyUp="RemoverCaracteresEspeciais(this.id);"
OnKeyPress="RemoverCaracteresEspeciais(this.id);"
onBlur="SomenteCaracteresNumericos(this.id);" usados nos 3 para evitar o Ctrl+V , Colar do Mouse ou digitar.
*/
function SomenteCaracteresNumericos(idControle) {
var texto = document.getElementById(idControle).value;
var textoSeparado = texto.split('');
var numeros = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
for (var i = 0; i < textoSeparado.length; i++) {
var teclaValida = false;
for (var j = 0; j < numeros.length; j++) {
if (numeros[j] == textoSeparado[i]) {
teclaValida = true;
}
}
if (!teclaValida)
textoSeparado[i] = '';
}
document.getElementById(idControle).value = textoSeparado.join('');
}
function Somente(idControle) {
var texto = document.getElementById(idControle).value;
document.getElementById('lblRefCNPJEmitenteFormatado').value = texto;
}
<asp:TextBox ID="txtRefCNPJEmitente" runat="server" Text="" placeholder=" " onFocus="javascript:this.select();" onkeypress="javascript:SomenteCaracteresNumericos(this.id);" onKeyUp="javascript:SomenteCaracteresNumericos(this.id);" onBlur="javascript:SomenteCaracteresNumericos(this.id);" onchange="javascript:Somente(this.id);">