views:

47

answers:

0

This question is in relation to A Previous Question, however, since it was a completely different I decided to start a new question.

In my code, i have a $(document).ready that calls a function addChild. It works just fine, unless I call the function more then once. If I call 2+ times in the $(document).ready, it will give the error:

Microsoft JScript runtime error: 'form' is null or not an object

  function addChild() {   $.ajax({ 
    type: "GET", 
    url: "/Home/AddChild?childNumber=" + $("#CurrentNumberOfChildren").val(), 
    data: "{}", 
    contentType: "text/html", 
    dataType: "html", 
    success: function (results) { 
      $('#ChildDiv').append(results); 
      $("#CurrentNumberOfChildren").val(parseInt($("#CurrentNumberOfChildren").val()) + 1); 
      var numberOfChildren = $("#CurrentNumberOfChildren").val(); 
      $("#BirthDate" + numberOfChildren).datepicker(); 
          $("#BirthDate" + numberOfChildren).rules("add", {
            required: true,
            messages: {
              required: "Birthdate for Kid #" + numberOfChildren + " is required"
            }
          });
    }   }); } 


<script type="text/javascript">
  $(document).ready(function () {
    addParticipant();
    addParticipant();
  });
</script>

The line it fails on is where I am adding the validator, but if I remove that line, the datepicker doesn't work either. Anyone have an idea why the form would be null?