Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input names that should not be used?

Earlier, I was creating a form and mindlessly named one of my inputs "name", similar to the following pseudo code:

<input id="name" type="text" name="name" />

I then remembered that in the past, I've had issues with inputs with the name "action." If I remember correctly, the issues arose during enhancement with JavaScript (there was confusion between the form's action and the input with the name "action").

So my questions are:

  • Is it safe to use something similar to the snippet above?
  • Is there some canonical list of strings that should generally NOT be used as input names?
like image 875
Jim D Avatar asked Apr 30 '13 20:04

Jim D


Video Answer


1 Answers

There's mostly problems if you're using shortcuts like myform.action as action is a property of the form element (like are id, parentNode, and some other properties you can see using console.dir(myform)).

You should always use the fast and reliable way :

var inputElement = document.getElementById('action');

or, using jQuery :

var $input = $('#action');

As noticed by epascarello, you'll also have problem if you call or use a property that you overrided by defining an element with that name, for example submit. But as you're the one calling it in your code, it should be obvious if it happens.

like image 166
Denys Séguret Avatar answered Nov 15 '22 00:11

Denys Séguret