Wednesday, December 12, 2012

Copy text in Jquery


Lets say we have two text boxes. One is a password textbox and other is a plain textbox. What we are going to achieve is when you type some text on the password text box and the focus goes out, the text you have typed in the password textbox will be appeared on the plain text box.

Below is our code.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="jquery-1.8.3.js" type="text/javascript"></script>
      <script type="text/javascript">
        $(document).ready(function () {
            $("#txthdnPassword").attr('readonly', 'readonly');
            $("#txtPassword").blur(function () {
                $("#txthdnPassword").val($(this).val());
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    Password: <input type="password" id="txtPassword" /><br />
    Password in Text: <input type="text" id="txthdnPassword" /><br />
    </form>
</body>
</html>

$("#txthdnPassword").attr('readonly', 'readonly');
Making the plain textbox read only.

$("#txtPassword").blur()

Capturing the event when the focus goes out from the password text box.

$("#txthdnPassword").val($(this).val());
Writing Password text to the plain textbox.

No comments:
Write comments
Recommended Posts × +