What NOT to Name Your Form Fields

This one is a programming post. Did you know you should never, ever, EVER name a field in your form “submit”. If you recall my previous posts, you’d recall that JavaScript can treat any old regular variable as a function. If you stupidly name your submit button “submit,” which I’ve seen done all the time, you overwrite your form’s ability to call the submit method!!!

Don’t do this:

<input type=”button” name=”submit” value=”push me” />

Or…

<input type=”text” name=”submit” value=”” />

Etc. It all messes up your JavaScript!

In other words, the following otherwise working function calls completely break (and you get cryptic errors about undefined functions or incorrect parameter counts):

document.form[‘form-name’].submit();
this.form.submit();
document.getElementById(‘form-id’).submit();

They all fail because “submit” now refers to your form field that you created, which clearly isn’t the function you thought you were calling!

2 thoughts on “What NOT to Name Your Form Fields”

  1. Sorry for commenting on such old blog post but there is a typo in your code.

    document.form[‘myForm’].submit(); should be document.forms[‘myForm’].submit();

    Other than that, nice article. 😉

Comments are closed.