-3

我正在使用 html 表单处理注册表单,但是我遇到了问题,当我输入错误的密码并输入 write past 时我的密码无法验证并没有显示任何内容,所以我应该怎么做?

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

3 回答 3

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");.

于 2013-09-11T07:51:35.700 回答
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!

这就是问题所在。

于 2013-09-11T08:19:58.403 回答
0

只是代码中的小改动

function validate(){
  var pass = document.getElementById("pwd").value;
  var pas1 = document.getElementById("cpwd").value;
  if (pass==pas1){
  }
  else{
    alert("Try again");
    return false;
  }
}
于 2013-09-11T08:01:39.113 回答