Change text of a label with javascript

0

Greetings. I have an Onblur event in Textbox :

<asp:TextBox ID="us" runat="server"  MaxLength="15" onblur="validar(this.id)" Width="232px"></asp:TextBox>

Then a Label :

<asp:Label ID="Label1" runat="server" Text="esto es un texto" ></asp:Label>

And a method in javascript:

<script> 

    function validar(x){
        //He intentado con: document.all("Label1").innerText = "Esto es otro texto"; Pero nada           
      //Incluso document.getElementById("Label1").innerHTML = "Esto es otro texto"; Y tampoco
    }          

</script>

How can I achieve this by either changing the text directly or enabling it from CSS every time I lose the focus of Textbox ?

    
asked by Necroyeti 21.07.2017 в 20:21
source

2 answers

1

With Javascript you can try

document.getElementById('<%=Label1.ClientID %>').innerHTML= 'Nuevo valor';

With jquery you can try

$('#<%=Label1.ClientID%>').html("Nuevo valor"); 
    
answered by 21.07.2017 в 20:26
0

Here's another way!

document.querySelector('#Label1').innerText = 'Tu Valor';

Greetings!

    
answered by 23.07.2017 в 04:59