You need to pass the ID of the control as a parameter of your javascript function.
For reference, see the code below.
Your Javascript file abc.js contains following
function abc(txtID) {
alert(document.getElementById(txtID).value);
}
HTML page contains,
<script src="abc.js" type="text/javascript"></script>
<asp:textbox id="txtInput" runat="server" ></asp:textbox>
<asp:button id="btn2" runat="server" text="Click Me" />
Then on your server side page load event
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
btn2.Attributes.Add("onclick", "abc('" + txtInput.ClientID + "')");
}
}
That's it, You are done.
Do Mark as Answer and Vote, if this solution works for you.