10

Given this HTML using jQuery validate

 <input id="accept-terms" type="checkbox" class="required"/> 
 <label for="accept-terms"> I accept the <asp:HyperLink ID="termsLink" runat="server" Target="_blank">terms and condtions</asp:HyperLink> of sale.</label>
 <label for="accept-terms" class="error-text">You must accept the terms and conditions before purchasing</label>

I get this error:

Uncaught TypeError: Cannot call method 'getAttribute' of undefined

Myster
  • 17,704
  • 13
  • 64
  • 93

1 Answers1

24

The 'name' attribute is missing:

<input id="accept-terms" name="accept-terms" type="checkbox" class="required"/> 

(This took me a while to figure out so I thought I'd share the question and solution)

Also: Check the comments below, as others have posted other causes for the same exception.

Myster
  • 17,704
  • 13
  • 64
  • 93
  • 3
    This can apparently also happen if you have a form inside of another form. – Farzher Nov 19 '12 at 16:30
  • i'm having the same problem with a TextArea which already has a attribute 'name' – mbmihura Jan 02 '13 at 14:19
  • Just read that it can also be because of a missing rule name. In my situacion, I've create a custom rule, that wasn't loading correctly, and the validator wasn't able to find it (so it threw the "Uncaught TypeError: Cannot call method 'getAttribute' of undefined") – mbmihura Jan 02 '13 at 14:32
  • just for posterity I was having this issue as well. For me it turns out I had mis-typed 'minlength' as 'minlengh'. Really wish I had those 4 hours back. Just wanted to put it here to check all spelling in case someone finds themselves in a simliar situation. – timmackay Feb 24 '13 at 06:27
  • For me, it was forgetting to call `e.preventDefault();` from inside a click listener attached to an `a` tag. The code was working, but the error was being logged. – Jimeux Nov 12 '14 at 14:15