验证密码无效

时间:2013-09-11 07:47:37

标签: javascript html

我正在使用html表单处理注册表单,但我遇到问题我的密码无法验证当我输入错误的密码并输入写过去没有显示任何内容所以我该怎么做任何帮助。

function validate(){
var = pass(document.getElementById("pwd").value;
var = pas1(document.getElementById("cpwd").value;
if (pass==pas1)
{
}
else
{
alert("Try again");
}
}
</script>
</head>
<body>
<p class="style2 style8">SIGN UP FORM!!!!</p>
<form onclick="validate()" action="insert.php" method="post">
  <table width="270" height="386" border="1" align="right" bordercolor="#993366" bgcolor="#CCCCCC"><td width="260"><table width="232" border="1">
    <tr>
      <td colspan="2"><span class="style2">loginform</span></td>
    </tr>
    <tr>
      <td width="72"><span class="style5">Name</span></td>
      <td width="144"><label>
        <input name="name" type="text" id="name" onblur="MM_validateForm('name','','R');return document.MM_returnValue" placeholder="Name" />
      </label></td>
    </tr>
    <tr>
      <td width="72"><span class="style5">Gender</span></td>
      <td><p>
        <label>
          <input type="radio" name="gender" value="Male" id="gender"/>
          <span class="style5">Male</span></label>
        <span class="style5" onfocus="MM_validateForm('fname','','R');return document.MM_returnValue"><br />
        <label>
<input type="radio" name="gender" value="female" id="gender" /> 
female</label>
        </span><br />
      </p></td>
    </tr>
  <td width="72"><span class="style5">DOB</span></td>
      <td width="144"><span id="sprytextfield1">
      <label>
      <input name="dob" type="text" id="dob" onblur="MM_validateForm('dob','','R');MM_validateForm('dob','','R');return document.MM_returnValue" placeholder="yyyy/mm/dd"/>
      </label>
      <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
  </tr>
  <tr>
    <td><span class="style5">Password</span></td>
    <td><label>
      <input name="pwd" type="password" id="pwd" onchange="MM_validateForm('pwd','','R');return document.MM_returnValue" placeholder="password"/>
    </label></td>
  </tr>
  <tr>
    <td width="72"><span class="style5">Confirm Password</span></td>
    <td width="144"><label>
      <input name="cpwd" type="password" id="cpwd" onchange="MM_validateForm('cpwd','','R');return document.MM_returnValue" placeholder="Confirm Password"/>
      </label>    </td>
  </tr>
  <tr>
    <td colspan="2"><label>
      <div align="center">
        <input type="submit" name="submit" id="submit" value="Signup" />
        </div>
    </label></td>
  </tr>
  </table>
    <label></label></td>
  </tr>
</table>
</form>
<h1>&nbsp;</h1>
<script type="text/javascript">
<!--
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "date", {format:"yyyy/mm/dd"});
//-->
</script>
</body>
</html>

3 个答案:

答案 0 :(得分:0)

嗯,对于初学者来说,

var = pass(document.getElementById("pwd").value;
var = pas1(document.getElementById("cpwd").value;

应该是

var pass = document.getElementById("pwd").value;
var pas1 = document.getElementById("cpwd").value;

编辑:

另外,将onclick="validate()"更改为onclick="return validate();"并在return false;之后添加alert("Try again");

答案 1 :(得分:0)

代码中的小变化

function validate(){
  var pass = document.getElementById("pwd").value;
  var pas1 = document.getElementById("cpwd").value;
  if (pass==pas1){
  }
  else{
    alert("Try again");
    return false;
  }
}

答案 2 :(得分:0)

您的内容中没有pass。你写的是:

var = pass(document.getElementById("pwd").value;
var = pas1(document.getElementById("cpwd").value;

应该是这个:

var pass = (document.getElementById("pwd").value;
var pas1 = (document.getElementById("cpwd").value;

因为变量的名称位于=符号之前。要表明此变量具有此值!

所以,现在让我们使用这个并尝试这样:

if(pass==pas1) {
  // save the password or whatever
} else {
  // please try again..
}

这样,用户将再次检查输入。他们没有工作。然后,您必须首先检查您是否使用了该元素的正确ID,或者您使用ClassName作为ID!

这就是问题所在。