【问题标题】:form onsubmit doesn't work end changing value of input表单 onsubmit 不起作用结束更改输入的值
【发布时间】:2015-06-30 11:14:33
【问题描述】:

我正在制作一个表格来更改密码。 我要求输入当前密码,然后有两个字段可以输入新密码。 我有两个问题: 首先:我需要检查新密码的两个字段是否相等。我使用onsubmit检查。如果它们相同,则提交。如果不一样,它应该显示一条消息说什么。问题是它没有显示。这是代码:

function checkform(){
    var pass=myForm.pass.value;
    var new=myForm.new.value;
    var new=myForm.new2.value;
    if(new!=new2){
       document.getElementById("message").style.display='block';
       document.getElementById("pass").value=" ";
       document.getElementById("new").value=" ";
       document.getElementById("new2").value=" ";
       return false;
     }else{
         return true;
     } 
}

当我插入不同的新密码时,它仍然会提交,但如果我删除了 document.getElementById,它不会提交。 第二个问题:我有一个 php 页面(不使用框架,只是 php),它是一个类。当我想访问该类的函数时,我需要做的就是

include("class.php");
$my = new the_class(); $response= $my->check();`

check() 函数检索密码,因此我可以检查字段 pass 中的值是否与 $response 相同。但是如何将它放在函数 checkform() 上?这样不行。

【问题讨论】:

  • 可能是复制和粘贴问题,但您将同一变量 new 设置为 newnew2 值。
  • 另外,new 是 JavaScript 中的保留关键字,因此您不应将变量命名为
  • stackoverflow.com/questions/3350247/… 使用此链接解决您的问题
  • 我已经看过那个帖子了不再

标签: javascript php forms onsubmit


【解决方案1】:

不要把变量名当作新的,它是为创建实例而保留的关键字,所以最好给变量取一些其他的名字,你可能会得到你要找的东西。

【讨论】:

  • 我以new为例,那不是名字...对不起,是我弄错了
  • Mar10Bel----- 我可以知道你没有使用 JQuery 来实现这个
  • 我贴的是我用的,没看懂问题
  • Mar10Bel---- 我明白了你的问题,我只是在问你。
【解决方案2】:
    **You Try below code**   

   function checkform(){
        var pass=myForm.pass.value;
        var new=document.getElementById("new").value();
        var new=document.getElementById("new2").value();
        if(new!=new2){
        document.getElementById("message").style.display='block';
        document.getElementById("pass").value=" ";
        document.getElementById("new").value=" ";
        document.getElementById("new2").value=" ";
            return false;
        }else{
            return true;
        } 
    }

【讨论】:

  • 仍然没有停止提交...这是onsubmit的html代码:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-08-14
  • 1970-01-01
  • 2018-08-06
  • 1970-01-01
  • 2015-11-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多