Keydown function does not work on aspx page.!

I am trying to add input on one textbox to another textbox at the same time using jquery keydown . For some reason its not working, I'm new to coding, so help and criticism will be appreciated ..!

code:

 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:Label ID="Label1" runat="server" Text="Text Box1"></asp:Label><br/> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br/><br/> <asp:Label ID="Label2" runat="server" Text="Text Box2"></asp:Label><br/> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </div> </form> <script> $('#TextBox1').keydown(function () { $('#TextBox2').val($(this).val()) }) </script> 

enter image description here

+5
source share
1 answer

You need to use Control.ClientID to get the identifier of the HTML markup control created by ASP.NET

 $('#<%= TextBox1.ClientID %>').keydown(function () { $('#<%= TextBox2.ClientID %>').val($(this).val()) }) 
0
source

Source: https://habr.com/ru/post/1268082/


All Articles