Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #15087

Re: submit()

From "Jukka K. Korpela" <jkorpela@cs.tut.fi>
Newsgroups comp.lang.javascript
Subject Re: submit()
Date 2012-07-17 13:04 +0300
Organization A noiseless patient Spider
Message-ID <ju3db0$q56$1@dont-email.me> (permalink)
References <qm7a081tvl82u7cbifdqebuog7bkbhi7v4@4ax.com>

Show all headers | View raw


2012-07-17 11:36, Swifty wrote:

> I have a form which is built like this:
>
> <FORM NAME=month METHOD=POST ACTION=xxxx>
> <TABLE>
> ...
> <TD onClick="submit()">...
> </TABLE>
> </FORM>
>
> It works, i.e. the submit() does submit the form, in all browsers
> except FireFox (both ESR 10 and 13.0.1)

It should not work - i.e., Firefox is correct -, because submit() is a 
property of the Form object, not global.

> If I change to onClick="document.month.submit()" then all of the
> browsers work, including both of my FireFoxes.

If JavaScript is enabled, that is. It is best to first consider using a 
normal submit button, possibly styled, rather than create a submit 
control of your own.

> In my brief research on "submit() not working firefox", the consensus
> is to add at least the form name, so why do the other browsers allow
> me to get away with a simple "submit()" (and what else could I be
> submitting?)

The consensus is questionable, as so often.

Browsers do odd things in trying to recover from errors.

It might be argued that error recovery is OK here, but it's really 
questionable. Programmers are not supposed to call methods of objects as 
if they were global, and if they do so, this may well reflect a design 
error that the programmer should be made aware of.

> Which of the following apply:
>
> (a) I was wrong to omit the "document.month." from my submit() ?
> (b) FireFox is in error by not actioning the unqualified submit() ?
> (c) This is a grey area, and no one is strictly wrong ?
> (d) Something else is going on ?

Well, (a) comes closest, but referring to a form by name is outdated. 
The id attribute is the modern way, for creating a unique identifier:

<form id="monthForm" ...>
...
onclick="document.getElementById('monthForm').submit()">

Alternatively, you could use

onclick="document.forms[0].submit()">

though it's a bit old-style, and it would make the code depend on the 
form being the first form on the page.

> Could I have used "this" in this scenario?

No, because "this" would refer to the node corresponding to the <td> 
element, and it has no "submit" method.

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

submit() Swifty <steve.j.swift@gmail.com> - 2012-07-17 09:36 +0100
  Re: submit() Martin Honnen <mahotrash@yahoo.de> - 2012-07-17 11:45 +0200
    Re: submit() Tim Streater <timstreater@greenbee.net> - 2012-07-17 11:36 +0100
    Re: submit() Martin Honnen <mahotrash@yahoo.de> - 2012-07-18 19:12 +0200
  Re: submit() SAM <stephanemoriaux.NoAdmin@wanadoo.fr.invalid> - 2012-07-17 12:03 +0200
  Re: submit() "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-07-17 13:04 +0300
    Re: submit() Swifty <steve.j.swift@gmail.com> - 2012-07-17 14:51 +0100
      Re: submit() "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-07-18 09:09 +0300
        Re: submit() Swifty <steve.j.swift@gmail.com> - 2012-07-19 17:27 +0100

csiph-web