最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Mask user input with asterisks - Stack Overflow

programmeradmin2浏览0评论

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 + "*";
        }
    document.getElementById(str.id).value = masked;
    }
}

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 + "*";
        }
    document.getElementById(str.id).value = masked;
    }
}
Share Improve this question edited May 5, 2011 at 14:46 Álvaro González 147k45 gold badges279 silver badges377 bronze badges asked May 5, 2011 at 14:42 WhizWhiz 211 silver badge2 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

<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)

  1. 暂无评论