最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery validation not firing - Stack Overflow

programmeradmin3浏览0评论

My form is using jquery validation. However, the validation is not firing. I am sure it is just a tiny mistake somewhere.. anyone?

Here is fiddle link /

BAsically here is my jquery validation code

$(document).ready(function () {
  <!-- validation -->
  $('#submitDetails').validate({
    // 1. validation rules.
    rules: {
      firstName: {
           required: true,
            maxlength: 120
      },
      lastName:{
           required: true,
            maxlength: 120
      },      
      custom1: {
           required: true,
            maxlength: 120
      },
      state: {
        required: true
      },
      custom9: {
        required: true
      },      
      email: {
        required: true,
        email: true
      }
    },
    // 2. Validation fail messages
    messages: {
      custom9: {
        required: "You must agree to the terms of conditions in order to participate."
      }
    },
    errorPlacement: function(error, element) {
        if (element.attr("name") == "custom9" )
            error.appendTo("#error_msg");               
        else
            error.insertAfter(element);
    }       
  });
  ///execute when submit button is clicked
  $("#submit").click(function () {

  });
});

My form is using jquery validation. However, the validation is not firing. I am sure it is just a tiny mistake somewhere.. anyone?

Here is fiddle link http://jsfiddle/2L6xT/

BAsically here is my jquery validation code

$(document).ready(function () {
  <!-- validation -->
  $('#submitDetails').validate({
    // 1. validation rules.
    rules: {
      firstName: {
           required: true,
            maxlength: 120
      },
      lastName:{
           required: true,
            maxlength: 120
      },      
      custom1: {
           required: true,
            maxlength: 120
      },
      state: {
        required: true
      },
      custom9: {
        required: true
      },      
      email: {
        required: true,
        email: true
      }
    },
    // 2. Validation fail messages
    messages: {
      custom9: {
        required: "You must agree to the terms of conditions in order to participate."
      }
    },
    errorPlacement: function(error, element) {
        if (element.attr("name") == "custom9" )
            error.appendTo("#error_msg");               
        else
            error.insertAfter(element);
    }       
  });
  ///execute when submit button is clicked
  $("#submit").click(function () {

  });
});
Share Improve this question asked Jan 20, 2014 at 0:07 Hello UniverseHello Universe 3,3027 gold badges56 silver badges91 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

In your html, the input element doesnot have name, the validator framework uses name to apply the rules

<input type="text" class="form-control" id="firstName" name="firstName" placeholder="First name" />

so along with id add name also(id is not required if it is not used elsewhere)

Demo: Fiddle

发布评论

评论列表(0)

  1. 暂无评论