Click here to Skip to main content
15,881,882 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.

XML
<script type="text/javascript">
         function a() {
             $('<%=lbldisplay.ClientID %>').html($('<%=txtdisplay.ClientID %>').val());
         }
     </script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <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();" />
    </div>
    </form>
Posted
Comments
Sanjay K. Gupta 7-Nov-12 0:14am    
You are missing '#' in jquery selector.

try this,
its working.

JavaScript
<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
    });
});    
</script>
 
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 '#':
http://api.jquery.com/id-selector/[^].

—SA
 
Share this answer
 
Hi,

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.
JavaScript
$("#<%= lblDisplay.ClientID %>").html($("#<%= txtDisplay.ClientID %>").val());

Thanks.
- 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