0

Issue:

jquery not picking up text/value from a ASP Label but does from a Textbox.

I have read up articles such as Get text of label with jquery and tried .val .value and .text

So if I put Label1 then nothing happens. If I put Label2 it works?!

<script type="text/javascript">
                            $(document).ready(function () {
                                $('#PropertyMap').showmap(document.getElementById('<%= Label1.ClientID%>').val);
                            });
                        </script>
                         <asp:Label ID="Label1" runat="server" Text="harrogate"></asp:Label>
                           <asp:Textbox ID="Label2" runat="server" Text="harrogate"></asp:Textbox>
Community
  • 1
  • 1
indofraiser
  • 1,014
  • 3
  • 18
  • 50

1 Answers1

1

An ASP:Label will be rendered as a span. To get the text of a span in JavaScript, you should change it to something like this:

$('#PropertyMap').showmap(document.getElementById('<%= Label1.ClientID%>').innerHTML);

Or, since you're using jQuery anyway:

$('#PropertyMap').showmap($('#' + <%= Label1.ClientID%>).text());
ZiNNED
  • 2,620
  • 20
  • 31