0

I've made a form where some of the elements are added using AJAX (post). You press a button to add the elements which are generated by a php page.

The jQuery validation (https://jqueryvalidation.org/) doesn't work on the elements that have been added using AJAX. I've tested the page replacing the AJAX elements with regular elements in the page and it works fine, so I think it's the AJAX.

Here's the jQuery:

  $("#editEventFormNew").validate (
    {
      rules: {
        artwork: { filesize: 2097152  },
        name:  {
          required: true,
          minlength: 2,
          maxlength: 50
        },
        desc: {
          required: true,
          minlength: 2,
          maxlength: 3000
        },
        venue2: {
          required: true
        },
        staDate: {
          required: true,
          //greaterThan: "dateHigherThanToday"
        },
        endDate: {
          required: true,
          greaterThan: "#staDate3"
        },
        cutDate: {
          required: true,
          lessThan: "#endDate3"
        },
        shoDate: {
          required: true,
          lessThan: "#staDate3"
        },
        totalSubCat: {
          minStrict: 0,
          maxStrict: 4
        },
      },
      messages: {
        name: "Enter the event name, longer than 2 and less than 50 characters",
        desc: "Enter a description, longer than 2 and less than 3000 characters",
        venue2: "Choose a venue",
        staDate: "Start must be after today",
        endDate: "End must be after the Start",
        cutDate: "Cut Off must be before the End",
        shoDate: "Show From must be before the Start",
        totalSubCat: "Choose between 1 and 3 categories"
      }
    }
  );

staDate, endDate, cutDate, shoDate are created using AJAX when a button on the form is pressed. The form elements are ignored by the jQuery.

  • Possible duplicate of [Event binding on dynamically created elements?](http://stackoverflow.com/questions/203198/event-binding-on-dynamically-created-elements) – emerson.marini Jun 01 '16 at 20:38
  • 1
    Related: [jQuery Validation plugin doesn't validate dynamically created form elements](https://stackoverflow.com/questions/18022224/jquery-validation-plugin-doesnt-validate-dynamically-created-form-elements) – Jonathan Lonowski Jun 01 '16 at 20:41
  • Are you calling that jQuery _after_ the form is populated? – Matthew Johnson Jun 01 '16 at 21:37
  • Yes I am called JQ after the form has been populated –  Jun 09 '16 at 09:59

0 Answers0