[英]prevent button form from submission Javascript
即使执行返回值,此表单也会继续提交,我的代码有什么问题?
function formhash (form, password)
{
var pass1 = document.getElementById("password").value;
var pass2 = document.getElementById("cpassword").value;
var ok = true;
if (password != cpassword) {
//alert("Passwords Do not match");
document.getElementById("password").style.borderColor = "#E34234";
document.getElementById("cpassword").style.borderColor = "#E34234";
ok = false;
return;
}
else
{
$.post('insert_home.php'
{PRIMAID:PRIMAID,EDITCAP:EDITCAP,EDITIMG:EDITIMG,EB_TITLE:EB_TITLE}).done(function(data){
alert ("Book Successfully Updated");
location.reload();
});
var p = document.createElement("input");
form.appendChild(p);
p.name="p";
p.type="hidden";
p.value=hex_sha512(password.value);
password.value="";
form.submit();
}
}
您正在调用form.submit();
,将其删除,它将不会提交。
您使用了错误的变量名“ password”和“ cpassword”。您创建了pass1
和pass2
因此需要使用它们。
更改为此:
//You were using the WRONG variable names
if (pass1 != pass2) {
//alert("Passwords Do not match");
document.getElementById("password").style.borderColor = "#E34234";
document.getElementById("cpassword").style.borderColor = "#E34234";
ok = false;
return false;
}
我看不到在哪里使用formhash()。
该代码调用提交,而不是函数。
如果提交表单,那是因为它处于else条件。
添加很多“ console.log(“ debug_X”)“,其中“ X”每次都是不同的数字。
您必须在console.log内部添加pass1和pass2的值。
也许您是用值代替对象,或者也可能发生相反的情况。
我的直觉告诉我要同时检查密码对象及其值。 它还告诉我,在向Don Rhummy发表评论之前,您没有检查pass1和pass2的内容。
请仔细检查,并在发布下一个答案之前进行更多搜索。
您可以通过执行“ console.log(pass1);”获得值。 并打开Firebug并检查javascript控制台。
从窗体中删除操作属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.