开发者

JS Making a specific word entered into a textbox trigger a password prompt that when correctly entered, you are directed to a new page

Making a specific word entered into a textbox trigger a password prompt that when correctly entered, you are directed to a new page.

Here is what I have so far. I could be way off the mark, but I would like to make it work somehow. This is just for fun, and really does not help in real life, but someone told me I couldn't do it, so now I'm trying to. Here's what I have.

<form id="form1">
<input type="text" id="txtInput" size="1" onblur="checkValue()" />
</form>

<script type="text/JavaScript">
function checkValue()
{
var txtCtrl = document.getElementById("txtInput");

var txtValue = txtCtrl.value;

if (txtValue == "test" || txtValue == "vgx" || txtValue == "vgc" || txtValue == "pcv" || txtValue == "开发者_如何学JAVApcg")
{
prompt('Enter Password','');
}
if (password != 'pass','password') 
{ 
window.location.href='http://google.com';
}
}
</script>

I'm really sorry I suck so much with JS, kinda new.

Many thanks, Danny


function checkValue()
{
    var txtCtrl = document.getElementById("txtInput");

    var txtValue = txtCtrl.value;

    if (txtValue == "test" || txtValue == "vgx" || txtValue == "vgc" || txtValue == "pcv" || txtValue == "pcg")
    {
        var password = prompt('Enter Password','');

        if (password == 'pass') 
        { 
            window.location.href='http://google.com';
        }
    }
}


This will not work because Javascript is visible to the client browser. That is, anyone can just view the source of your page and see your entire script, including the password.

Consider using a database, or at the very least store/retrieve your password from a file located outside of your document directory.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜