Click here to Skip to main content
15,668,517 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am practicing jquery here i want to display textbox value into label. But its not displaying here is my code. I am not finding out the error.

<script type="text/javascript">
         function a() {
             $('<%=lbldisplay.ClientID %>').html($('<%=txtdisplay.ClientID %>').val());
    <form id="form1" runat="server">
        <asp:Label ID="lbldisplay" runat="server"></asp:Label><br />
        <br />
        <asp:TextBox ID="txtdisplay" runat="server"></asp:TextBox><br />
        <asp:Button ID="btnsubmit" runat="server" Text="Submit" OnClientClick="function a();" />
Sanjay K. Gupta 7-Nov-12 0:14am    
You are missing '#' in jquery selector.

try this,
its working.

<script type="text/javascript">
$(document).ready(function () {
  $('#<%=btnsubmit.ClientID %>').click(function (e) {
     $('#<%=lbldisplay.ClientID %>').text($('#<%=txtdisplay.ClientID %>').val());
//.text("value") use to set text value. of the div or span.
       e.preventDefault(); //to prevent form submission
Share this answer
First bug I can see is in the $(...) selector. You are trying to find an element by id, and in jQuery, this is a id selector, should be prepended with '#':[^].

Share this answer

You are missing '#' before the control identifiers since you are using jQuery. These are important since you are referring to the id attribute of the text/label control.
$("#<%= lblDisplay.ClientID %>").html($("#<%= txtDisplay.ClientID %>").val());

- Steven
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900