I am using a ASP.NET(3.5) page and I have a text box called txtName.
I want to read the value with JavaScript like so but it does not work.
var Name = document.getElementById(txtName).value;
alert(Name);
Even this does not want to work:
var Name = document.FormName.txtName.Value;
alert(Name);
This work with plain HTML pages but not with my ASP.NET page, why?
It sounds like
txtNameis the server-side ID of your control. ASP.NET will use a different client-side ID when it renders the control as HTML: probably something likectl00_Container_txtName.You need to use the control’s
ClientIDproperty to get the client-side ID, and then use that in yourgetElementByIdcall: