开发者

Mask user input with asterisks

开发者 https://www.devze.com 2023-03-03 07:52 出处:网络
I am trying to implement a simple input mask js which will replace asterisks for any sensitive user data on the form like the social#. However, this might sound like a very stupid question, when i wan

I am trying to implement a simple input mask js which will replace asterisks for any sensitive user data on the form like the social#. However, this might sound like a very stupid question, when i want to submit the form, i want to send the actual value of the textfield, the user entered. How do i go about doing that? I want to avoid submitting asterisks as the textfield value

function mask(str) {
    if(str.value!=null || str.value!="") {
        num = str.value.length;
        var masked = "";
        for(i=0; i<num; i++) {
            masked = masked + "开发者_Go百科*";
        }
    document.getElementById(str.id).value = masked;
    }
}


<input type="password" /> will do this for you automatically, no need to reinvent the wheel


Given your feedback, what about a middle-road? Keep the input box visible until text has been entered, then hide the input box when it loses focus and show a UI element to allow the user to bring the box back if needed.


Here's a quick proof-of-concept

0

精彩评论

暂无评论...
验证码 换一张
取 消