Closed Bug 72156 Opened 23 years ago Closed 23 years ago

form.submit() doesn't work with <input name="submit">

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

VERIFIED INVALID

People

(Reporter: mozbug1, Assigned: jst)

References

()

Details

From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux 2.4.2 i686; en-US; 0.8) Gecko/20010215
BuildID:    2001021503

When there is a button named 'submit' trying to call form.submit() from
javascript fails with an error like:

JavaScript error: 
http://www.selectacast.net/~jks/mozillatest4.html line 14: object is not a function

Reproducible: Always
Steps to Reproduce:
Go to http://www.selectacast.net/~jks/mozillatest4.html.  Bug happens with
submit button named "submit".  I haven't checked if other types of <input>s also
break but I imagine that they do.

Actual Results:  I get an error message on the console:

JavaScript error: http://www.selectacast.net/~jks/mozillatest4.html line 14:
object is not a function

Expected Results:  The form should submit.

68321 might possible be related to this.  According to the discussion there it
sounds like they have yet to find the cause of that problem. It doesn't really
sound like it is related to this one, but it just might be.
Well, form.submit has to be a DOM object.  Once you've created an input element
called 'submit', form.submit can no longer be a function -- it's now that input
object.

NS 4.x exhibits the same behavior (does not submit).  I'm surprised IE does not
-- this leads to an interesting inconsistency if one does "alert(form.submit)",
does it not?

Recommend invalid, but over to DOM0 to be looked at.
Assignee: rogerl → jst
Component: Javascript Engine → DOM Level 0
QA Contact: pschwartau → desale
Agreed marking INVALID.
Status: UNCONFIRMED → RESOLVED
Closed: 23 years ago
Resolution: --- → INVALID
Well I don't agree.  Why can't there be a form.submit() function just because
there is a form.submit input field?  There can be multiple inputs named submit
that don't interfere with each other, so why do they interfere with the function?
The javascript engine should be smart enough to figure out which submit is the
function.

-- jks, A functional programmer used to strict types lost in script land
Since the beginning of time (in JavaScript land) the order in which names are
resolved on form objects has been to first look for a property with that name on
the form object itself and if it's not found there then go up the form object's
prototype chain looking for the named prperty. The first one found wins,
obviously, and form controls that are bound to a form are found on the form
object itself (since object prototypes are shared between objects of the same
class) and thus they shadow predefined form properties (which are all found on
the prototype chain of the form object). This is the natural order of name
resolution in JS, IE's JavaScript implementation in broken, but that's IE's problem.

If you wanto avoid this, don't use the name of predefined form properties as
form control names. Yes, you can have multiple inputs with the same name,
'submit' if you like, and they don't interfere with each other (since there's no
relationship between sibling form controls as there is between forms and their
form control), but also they shadow predefined properties on their form object,
in this case form.submit would be an array of the input controls named 'submit'.

Mozilla is no different wrt property lookup on form object's than any previous
version of Netscape, AFAIK.
Yes I understand that is how it works but I'm saying that isn't how it *should*
work, since to my mind the "()" after submit should be the clue to javascript
that it is looking for a function, and should keep looking until it finds
something that can be called as a function.  The ecma standard isn't clear on
the issue.
form.submit(); is simply a property lookup on the form element (at which time we
don't know that we're looking for a function), once the property is found we get
the value of the property and we try to call it and if the value is not a
function, the call can't be made.

Imagine this (which won't work in the mozilla DOM, but is ok in ECMAScript in
general):

  var a = form.submit;

  ...

  a();

Now what would you do? A function is just a property on an object, just like any
other property.
VERIFIED dup
Status: RESOLVED → VERIFIED
*** Bug 125242 has been marked as a duplicate of this bug. ***
*** Bug 278407 has been marked as a duplicate of this bug. ***
*** Bug 281193 has been marked as a duplicate of this bug. ***
*** Bug 319295 has been marked as a duplicate of this bug. ***
You need to log in before you can comment on or make changes to this bug.