javascript - Show password checkbox in ASP.NET MVC 4 -
how show or hide password on click of checkbox? model class-
public partial class user { [required] public string username { get; set; } [required] [datatype(datatype.password)] public string password { get; set; } }
and in view have done -
@html.editorfor(model => model.password, new { htmlattributes = new { @class = "form-control" } })
so want add checkbox show , hide password.
i searched can done of javascript in webform changing 'type' 'password' 'text' on click of checkbox here in mvc have mentioned datatype in model class. there way can change text using jquery or javascript?
you can same thing in asp.net mvc since client side javascript. razor uses attributes render input elements. once rendered browser, can on rendered output client side javascript.
assuming have checkbox id showpass
@html.editorfor(model => model.password, new { @class = "form-control" } ) <input type="checkbox" id="showpass"/>
now, listen change
event on checkbox , if true, update input element's type
attribute value.
$(function() { $("#showpass").change(function() { var checked = $(this).is(":checked"); if (checked) { $("#password").attr("type", "text"); } else { $("#password").attr("type", "password"); } }); });
Comments
Post a Comment