开发者

Validate upon submit

开发者 https://www.devze.com 2023-01-26 16:35 出处:网络
$(\"#sbmit\").click(function(){ $(\":text[name^=\'1stfld\']\").each(function(i, laman){ var $current = $(this);
          $("#sbmit").click(function(){
              $(":text[name^='1stfld']").each(function(i, laman){

                  var $current = $(this);                 
                  $('input[name^="1stfld"]').each(function() {
                      if ($(this).val() == $current.val() && $(this).attr('id') != $current.attr('id')) {
开发者_运维技巧                        alert('Duplicate Found!');
                        $(this).addClass("xrequired");
                        return false;
                      }else{
                        $(laman).removeClass("xrequired"); 
                      }               
                  });   

                  if ($(this).val() == "") {
                      alert("wala");
                      $(laman).addClass("xrequired");
                      $(laman).focus();
                      return false;
                  }else{
                      $(laman).removeClass("xrequired"); 
                  }

                  $("#form").submit();

              });

How can I optimized this?


Perhaps you want to have a look at the excellent jQuery validation plugin: http://bassistance.de/jquery-plugins/jquery-plugin-validation/

The creator of this plugin is a ninja in jQuery, so you can expect that his code is excellent (Microsoft uses his plugin in their ASP.NET MVC platform).

0

精彩评论

暂无评论...
验证码 换一张
取 消