1

Am trying to add input on one textbox to other textbox on same time using jquery keydown . For some reason its not working, Am new to coding so helps 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

Aju
  • 503
  • 1
  • 8
  • 26

1 Answers1

0

You need to use Control.ClientID to get the control ID for HTML markup that is generated by ASP.NET

$('#<%= TextBox1.ClientID %>').keydown(function () {
    $('#<%= TextBox2.ClientID %>').val($(this).val())
})
Satpal
  • 132,252
  • 13
  • 159
  • 168