Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
<textarea id="txt_area" class="TextArea" name="textarea"  maxlength="256"></textarea>

at run time when user try to enter anything inside the above text area, it should display password format or special characters e.g.: *********
Posted
Comments
_Asif_ 10-Feb-15 1:41am    
Why is it necessary to use textarea? why cant a standard input box?
Member 10081852 10-Feb-15 4:40am    
My requirement is with TextArea only :(

1 solution

Below is a small sample that i tried. This is not the exact solution but it might be useful. There are several things you might have to take care
- when user enters characters
- when user selects the whole text and enters
- when the user presses backspace (select all and delete)
etc. ..

HTML
<html>
    <head>
        <title></title>
    </head>
<body>
    <textarea id="txtArea" class="TextArea" name="textarea"  maxlength="256"></textarea>
    <input type="button" value="Get Value" />
<script type="text/javascript" src="../Scripts/jquery-1.7.1.js"></script>
<script type="text/javascript">
    $(function ($) {
        var text;
        $('#txtArea').keyup(function (e) {
            if (text) {
                text += $(this).val().replace(stars.substring(0, stars.length - 1), "");
            } else {
                text = $(this).val().replace(stars.substring(0, stars.length - 1), "");
            }
            ShowCharacter();
        });

        var stars;
        $('#txtArea').keydown(function () {
            if (stars)
                stars += '*';
            else
                stars = '*'
        });

        function ShowCharacter() {
            $('#txtArea').val(stars)
        }

        $("input[type='button']").click(function () {
            alert(text);
        });

    });
</script>
 
</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900