We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

sdd

Hi guys,

Using EJ2, MVC5, VS2017

Is there a way to have a toggle button to show/hide input password in TextBox component?

 @Html.EJS().TextBox("Password").Placeholder("Senha").FloatLabelType(FloatLabelType.Auto).Type("Password").Render()


Thank you

1 Reply

PO Prince Oliver Syncfusion Team April 30, 2019 08:45 AM UTC

Hello Vanderlei, 

Greetings from Syncfusion support. 

Yes, you can use the button to show and hide the input password in TextBox component. You need to use the type property in textbox and set its value respect to the toggle button’s content. Kindly refer to the following code snippet. 

@Html.EJS().TextBox("Password").Placeholder("Senha").FloatLabelType(FloatLabelType.Auto).Type("Password").Render() 
        <button id="Reveal">Show</button> 
 
<script> 
    document.getElementById('Reveal').onclick = function () { 
        var textObj = document.getElementById("Password").ej2_instances[0]; 
        var togglebtn = document.getElementById("Reveal"); 
        if (textObj.type == 'Password') { 
            textObj.type = "Text"; 
            togglebtn.textContent = 'Hide'; 
        } else { 
            textObj.type = "Password"; 
            togglebtn.textContent = 'Show'; 
        } 
    }; 
</script> 
  
Let us know if you need any further assistance on this. 

Regards, 
Prince 


Loader.
Up arrow icon