I tried all the possible solutions to get the value of an element by id, but it did not work. I am using ASP.NET, I have searched for the controls and I know that the server changes the id of the TextBox1
, so we use the clientID
. But when I write console.log(data1), I get nothing or empty space.
var data1 = document.getElementById('MainContent_TextBox1').textContent;
var data1 = document.getElementById(<%=MainContent_TextBox1.ClientID %>).value;
This is the ASPX code:
<asp:TextBox ID=TextBox1 runat=server ></asp:TextBox>
And this the JS code:
var data1 = document.getElementById('MainContent_TextBox1').textContent;
In the console, I get this error:
Uncaught SyntaxError: Unexpected end of input and its reference in the master file!
console.log(data1);
appears in the console as empty place.
If anyone knows another way or why it is not working, please tell me.