0

I have an asp control for a textbox and a script that's trying to get the value from the textbox but it wont fire the alert:

<asp:TextBox ID="txtEmailList" runat="server" TextMode="MultiLine"></asp:TextBox>

<script>
    $(document).ready(function () {
        $("#btnCopyAll").click(function () {
            alert(document.getElementById('#txtEmailList').value);
        });
    });
</script>

I tried:

alert(document.getElementById('<%txtEmailList.ClientID%>'));

As per this answer, but it did not work.

How do I accomplish this?

1
  • Try this alert($("#txtEmailList").val()); Commented Apr 17, 2019 at 14:06

3 Answers 3

0
alert(document.getElementById('#txtEmailList').value);

Should be:

alert(document.getElementById('txtEmailList').value);
Sign up to request clarification or add additional context in comments.

Comments

0

Your first attempt

alert(document.getElementById('#txtEmailList').value);

failed because you are using '#'. When using getElementById you just need the id without '#' so you could try

alert(document.getElementById('txtEmailList').value);

Your second attempt

alert(document.getElementById('<%txtEmailList.ClientID%>'));

failed because you have not used .value, so you could try

alert(document.getElementById('<%=txtEmailList.ClientID%>').value);

Let me know how it goes.

Comments

0

You can use JQuery to fetch the contents of the list using the val() method. $("#txtEmailList") selects the list:

alert($("#txtEmailList").val());

Comments