简体   繁体   English

针对另一个SELECT PHP JQuery验证SELECT

[英]Validate a SELECT against another SELECT PHP JQuery

Within my form there are 2 SELECT Options. 在我的表单中有2个SELECT选项。 I'm looking to check the values of both, to check that they match. 我想检查两者的值,以检查它们是否匹配。

This below is my jquery, when the code runs, I deliberatly have different values in the SELECT options and the form will just carry onto the next page without flagging up the error that they don't match. 下面这是我的jquery,当代码运行时,我deliberatly必须在SELECT选择不同的价值观和形式会而已矣到下一页毫不气馁了错误,他们不匹配。

     <script  type="text/javascript">
      $(document).ready(function () {     
        jquery(function(){
            $("leadgenform2").click(function(){
               $(".error").hide();
                var hasError = false;
                var exppagesval = $("#exppages").val();
                var pagesseenval = $("#pagesseen").val();
                if (exppagesval != pagesseenval) {
                   $("#pagesseen").after('<div class="alert alert-success display-hide"><button class="close" data-close="alert"></button>Pages Seen & Expected Pages do not match!</div>');
                  hasError = true;
                }
                if(hasError == true) {return false;}
            });
         });
   });      
</script>

What have I missed? 我错过了什么?

Not sure why formatting has gone a miss. 不知道为什么格式化错过了。 sorry! 抱歉!

hey $("leadgenform2") is invalid selector either make it a class or id(preferred) and use like 嘿$(“ leadgenform2”)是无效的选择器,请将其设为类或id(首选)并使用类似

  • $(".leadgenform2") for class. $(“。leadgenform2”)用于类。
  • $("#leadgenform2") for id. $(“#leadgenform2”)for id。

Just from a first glance... you seem to have an error on line1: 乍一看...您似乎在第1行出现错误:

jquey(function(){

should be 应该

jquery(function(){

And you are missing $(document).ready(function(){ .... ); 而且您缺少$(document).ready(function(){ .... ); Without this, click event will not fire. 没有此操作,click事件将不会触发。

$("leadgenform2") is not a valid selector. $(“ leadgenform2”)不是有效的选择器。 assuming it is an ID, so you should use $("#leadgenform2"). 假设它是一个ID,则应使用$(“#leadgenform2”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM