# Show and Hide Passwords in a TextBox

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC TextBox</td>
 </tr>
 <tr>
  <td>Progress Telerik UI for ASP.NET MVC version</td>
  <td>Created with the 2022.2.621 version</td>
 </tr>
</table>

## Description

How can I toggle sensitive data, such as passwords, so that the user can preview the entered input?

## Solution

1. Add a `button` or a `span` element and handle the `click` event for it.
2. In the event handler, change the `type` attribute of the TextBox to `text` or `password` so that the text is displayed or obscured.

```Razor Index.cshtml
    @(Html.Kendo().TextBox()
        .Name("textbox")
        .Placeholder("Password")
        .Value("myBigS1cret")
        .HtmlAttributes(new { type = "password" })
    )
    <span toggle="textbox" class="k-icon k-i-eye toggle-password"></span>
```

```JS script.js
    <script>
        $(document).ready(function(){
            $(".toggle-password").click(function () {
                $(this).toggleClass("k-i-minus k-i-eye"); //toggle the current icon
                var input = $("[id='" + $(this).attr("toggle") + "']"); //get the input

                if (input.attr("type") === "password") { //change the input type
                    input.attr("type", "text");
                } else {
                    input.attr("type", "password");
                }
            });
        });
    </script>
```

For the complete implementation of the suggested approach, refer to the following [Telerik REPL](https://netcorerepl.telerik.com/GckrEqvI37R0V54u19) example.

## More ASP.NET MVC TextBox Resources

* [ASP.NET MVC TextBox Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/editors/textbox/overview)

* [ASP.NET MVC TextBox Demos](https://demos.telerik.com/aspnet-mvc/textbox)

* [ASP.NET MVC TextBox Product Page](https://www.telerik.com/aspnet-mvc/textbox)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Telerik REPL: Show and Hide Passwords in TextBox](https://netcorerepl.telerik.com/GckrEqvI37R0V54u19)
* [Client-Side API Reference of the TextBox for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/textbox)
* [Server-Side API Reference of the TextBox for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/textbox)
* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)
* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
