How to assign the textbox value to a javascript variable?

-1

I have my text box in html :

<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Height="200px" Width="1000px" BackColor=""></asp:TextBox>

and I want to assign the value to a variable that I have in Javascript :

var nombre1 = 
    
asked by Aprendiendox 15.03.2018 в 18:00
source

3 answers

1

Keep in mind that the IDs generated by WebForms on the client side have a "rare" form, this is to keep all unique IDs, therefore:

var nombre1 = $('#<%= TextBox1.ClientID %>').val();
    
answered by 15.03.2018 в 18:28
1

Hello with jquery is easy

<input type=" text" id="algo "/> 

var algo = $(selector).val();

I hope it works for you

Greetings.

    
answered by 15.03.2018 в 18:11
0

If you use both a

<input id="id_etiqueta"> o <textarea id="id_etiqueta">

You can capture the value with

var nombre1 = document.getElementById("id_etiqueta").value;

or assign the value

document.getElementById("id_etiqueta").value = "Valor Nuevo";
    
answered by 15.03.2018 в 18:08