I am trying to use JavaScript to get the value from an HTML text box but value is not coming after white space
For example:
Set the id
attribute of the input
to txtJob
. Your browser is acting quirky when you call getElementById
.
If you are using ASP.NET, the server-side code tags in these examples below will provide the exact control ID, even if you are using Master pages.
Javascript:
document.getElementById("<%=MyControlName.ClientID%>").value;
JQuery:
$("#<%= MyControlName.ClientID %>").val();
If you are using any user control and want to get any text box values then you can use the below code:
var result = document.getElementById('LE_OtherCostsDetails_txtHomeOwnerInsurance').value;
Here, LE_OtherCostsDetails
, is the name of the user control and txtHomeOwnerInsurance
is the id of the text box.