Changing a Label control when changing a textbox control

Asked

Viewed 307 times

2

I have a textbox control that is used to receive a CPF or CNPJ and in it and made a check to accept only numbers. The label that is 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 is already been saved and the user modifies the CPF or CNPJ change the value of the label when the textbox loses Focus. I’m already using Usage: onKeyUp, Onkeypress and onBlur, are used in the 3 to avoid Ctrl+V , Paste Mouse or type, everything is done in javascript. No onblur can call 2 Function and how to take the value of textbox and play on the label by javascript?

Thank you that you can 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);">

1 answer

1

Uses the onchange, then to take the value uses =

var value = document.getElementById('idinputcpf').value;

And to set the value to the label uses =

document.getElementById('idlabel').value = '';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.