Javascript密码提交-表格 [英] Javascript Password Submit - Form

查看:117
本文介绍了Javascript密码提交-表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为表单设置密码.我基本上希望有人在密码字段中键入密码,然后单击提交",如果密码正确,它将把他们重定向到同一窗口中的buybutton.php.如果密码不正确,则会弹出一个JavaScript警报,提示密码错误".我试图写出Javascript,但是当单击按钮时没有任何动作发生.我在下面的代码中做错了什么?感谢您的帮助!

I am trying to set a password to a form. I basically want someone to type a password into a password field and hit submit and if the password is right, it redirects them to buybutton.php in the same window. If the password isn't right, a javascript alert pops up that says 'Password wrong'. I've tried to write out the Javascript but no action is happening when the button is clicked. What have I done wrong in my code below? Thanks for the help!

<!DOCTYPE html>
<body width="950" height="300" style="background-image:url('giftcard_bg.jpg');">
<head>
<SCRIPT LANGUAGE="JavaScript">
    function goForit() {
      var passwd;
      passwd = this.document.giftForm.pass.value;
      if(passwd=="samsamsam"){
      window.open ('buybutton.php','_self',false)
      }
      else{
      alert('Password wrong');
      }
    }
</SCRIPT>
</head>


<div style="position:absolute; top:150px; left:285px; text-align:center;">
    <form id="giftForm">        
        <input type="password" id="pass" placeholder="Enter Secret Code" style="font-size:150%;"/>
        <br />
        <input type="button" onClick="goForit()" value="Submit" style="font-size:150%; margin-top:15px;" />                 
     </form>
</div>

</body>
</html>

推荐答案

passwd = this.document.giftForm.pass.value; 

导致错误尝试

passwd = document.getElementById('pass').value;

在窗口之后,您也错过了;.打开('buybutton.php','_self',false)

You were missing a ; too after window.open ('buybutton.php','_self',false)

这篇关于Javascript密码提交-表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆