Tuesday, July 5, 2011

Submit button name when posting form in JS

I am sure plenty of people out there have had this issue. So I had a submit button named "submit" and tried to do form submit in js by doing $("#theform").submit(); and I kept getting this error saying that .submit() wasn't a function. After some digging apparently if you name a submit button in a form "submit" it overwrites the submit() with submit button element. Not cool.

2 comments:

  1. You probably shouldn't name your DOM elements generic names like "button" or "table". Javascript get's confused easily.

    ReplyDelete
  2. True, I was assuming it would know the difference between an element and a function call. I assumed too much apparently.

    ReplyDelete