By 06/02/2014 3 Comments

How To Clone the Contents of ASP.NET TextBox into other ASP.NET TextBoxes using jQuery

What is clone ?

  • Make a copy of one textbox’s value and  paste / set same text in other textboxes  as a value that process is called clone

Clone the contents

  • As the user types in the first TextBox, we retrieve the value of the first TextBox and set it to the value of the all other TextBoxes

Following code describes the cloning of one textBoxe’s value to another textBoxe’s value in asp.net using jquery

JQuery Code snippet

<script type="text/javascript" src="Scripts/jquery-1.8.2.js"></script> <!-- call jquery file or library into asp.net page --->
    <script>
        $(document).ready(function() { // this is a function which is called by browser when it loads a webpage

            $('[id$="TT_TextBox1"]').keyup(function () { // get textBox_1 object, trigger it's keyup event and call anonymous function
                var txtClone = $(this).val(); // get the value of textBox_1 using val() function, assign it into txtClone variable

                $('[id$="TT_TextBox2"]').val(txtClone);

                $('[id$="TT_TextBox3"]').val(txtClone); // clone or set first's textBox value to other 3 textBox as its value by passing txtClone fron val() method

                $('[id$="TT_TextBox4"]').val(txtClone);

            });

        });

    </script>

ASP.NET Code snippet

 <!--- Following is the code which renders the textBoxes and a label control on browser-->

<asp:Label runat="server" Text="Enter text in the top textbox to see it cloned in the all bottom textboxes"></asp:Label>
        <br/>
        <asp:TextBox ID="TT_TextBox1" runat="server" Text="" /><br /><br />
        <asp:TextBox ID="TT_TextBox2" runat="server" Text="" /><br /><br />
        <asp:TextBox ID="TT_TextBox3" runat="server" Text="" /><br /><br />
        <asp:TextBox ID="TT_TextBox4" runat="server" Text="" /><br /><br />






Posted in: ASP.NET, jQuery

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .