gpt4 book ai didi

javascript - document.getelementbyid 返回输入类型未定义

转载 作者:行者123 更新时间:2023-12-03 07:45:50 26 4
gpt4 key购买 nike

我有一个简单的更改密码表单,其中包含一些用于验证表单的脚本。问题是当我调试表单时,带有 id=password 的输入字段返回未定义。我哪里做错了?如有任何建议,请。

  <?php
if(isset($_POST['submit_pass']))
{
$password=mysql_real_escape_string($_POST['password']);
$confirmpasssword=mysql_real_escape_string($_POST['confirmpassword']);
if($password==$confirmpasssword)
{
$email=$_SESSION['login_email'];
$insert=("update customers set password='$confirmpasssword' where email='$email'");
$insert1=mysqli_query($con,$insert);
echo "<script> alert('Your password is changed');</script>";
}
else
{
echo "<script> alert('Your password is not changed');</script>";
}
}
?>
<script type="text/javascript">
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","check_password.php?q="+str,true);
xmlhttp.send();
}
</script>

<script type="text/javascript">
function pass()
{
var cpwd=document.getElementById("confirmpassword").value;
var pwd=document.getElementById("password").value;
if(pwd==cpwd)
{
var t1=document.getElementById('pass').innerHTML="Password Match";
}
else
{
var t1=document.getElementById('pass').innerHTML="Password does not Match";
document.form.password.focus();
}
}
</script>



<div id="password" class="tab-pane fade">

<form id="form_setup" name="form_setup" method="post" action="" onSubmit="return passvali();">
<table width="50%" border="0" cellspacing="0" cellpadding="5" align="center" bgcolor="#C1C1FF">
<tr>
<td colspan="2" align="center"> <h2>Change Password</h2></td>
</tr>
<tr>
<th> Current Password <span style="color:#F00;">*</span></th>
<td><input type="password" name="cur_pwd" class="input" id="oldpassword"placeholder="Enter Current Password" onChange="showUser(this.value)" /></td>
<td> <span class="st" id="txtHint"></span> </td>
</tr>
<tr>
<th>New Password <span style="color:#F00;">*</span></th>
<td><input type="password" name="password" class="input" id="password" placeholder="Enter your Password"/></td>
</tr>
<tr>
<th> Confirm Password <span style="color:#F00;">*</span></th>
<td><input type="password" name="confirmpassword" class="input" id="confirmpassword" placeholder="Enter Confirm Password" onChange="return pass()" /></td>
<td><span id="pass" style="color:#F00;"> </span> </td>
</tr>
<tr>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit_pass" value="Submit" style="width:80px;" /></td>
</tr>
</table>
</form>


</div>

最佳答案

您有两个带有 id="password" 的元素:

enter image description here

ID 必须是唯一的。

关于javascript - document.getelementbyid 返回输入类型未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35210834/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com