jQuery and ASP.NET

May 22, 2009

Copy Text From One ASP.NET TextBox To Another




Here's a simple way of copying Text From One ASP.NET Text Box to Another as the user types, using JavaScript

Add the following TextBox to your page


<asp:TextBox ID="txtOne" runat="server" onkeyup="OneTextToOther();"></asp:TextBox>


<asp:TextBox ID="txtTwo" runat="server"></asp:TextBox>




Now add the following JavaScript in the <head> section of your page


<head>


    <title></title>


    <script type="text/javascript">


        function OneTextToOther() {


            var first = document.getElementById('<%= txtOne.ClientID %>').value;


            document.getElementById('<%= txtTwo.ClientID %>').value = first;


        } 


    </script>


</head>




'Like' us on our FaceBook page if you find this blog useful. Thanks!


Did you like this post?
kick it on DotNetKicks.com Save on Delicious
subscribe via rss subscribe via e-mail
print this post follow me on twitter


About The Author

Suprotim Agarwal, ASP.NET Architecture MVP works as an Architect Consultant and provides consultancy on how to design and develop Web applications.

Suprotim is also the founder and primary contributor to DevCurry, DotNetCurry and SQLServerCurry. He has also written an EBook 51 Recipes using jQuery with ASP.NET Controls.

Follow him on twitter @suprotimagarwal

comments

1 Response to "Copy Text From One ASP.NET TextBox To Another"
  1. Zoran said...
    October 4, 2009 3:12 AM

    Excellent! Thank you.

 

Copyright © 2009-2011 All Rights Reserved for DevCurry.com by Suprotim Agarwal | Terms and Conditions