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?

3 Answers3

0

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

alert($("#txtEmailList").val());
Bob Dalgleish
  • 8,167
  • 4
  • 32
  • 42
Divya Agrawal
  • 300
  • 1
  • 2
  • 15
0
alert(document.getElementById('#txtEmailList').value);

Should be:

alert(document.getElementById('txtEmailList').value);
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.

prinkpan
  • 2,117
  • 1
  • 19
  • 32