Submiting a form using javascript

B

bizt

Hi,

First let me point out I have googled this and also must have done
this operation a dozen times (altho a few years ago) but for some
reason I cant get a form to submit using javascript .. Ive tried both
FF and IE. All the pages that I look at all say the same way which is
the way Im sure Ive done it before:


My code is:

(javascript function)

function DeleteImages (oForm) {
alert('submitting form') // this works ...
oForm.submit() // this doesnt!!
}

(html button)

<input type="button" name="submit" value="Delete Selected"
onclick="DeleteImages(this.form);" />


Maybe just a sanity check is needed but I cant see what the problem
is. Where am I going wrong? I know that the function is being called
because the alert message is executing but the form isnt submitting.

Cheers

Burnsy
 
R

RobG

First let me point out I have googled this and also must have done
this operation a dozen times (altho a few years ago) but for some
reason I cant get a form to submit using javascript .. Ive tried both
FF and IE. All the pages that I look at all say the same way which is
the way Im sure Ive done it before: [...]
<input type="button" name="submit" value="Delete Selected"
onclick="DeleteImages(this.form);" />

Browsers make named controls available as properties of the DOM form
object. Giving any control a name of 'submit' shadows the form's
submit method, so form.submit() is equivalent to
form.elements['submit']().

There is rarely any need to name a submit button, remove the name (or
change it to something other than 'submit') and life will return to
normal...
 
G

Gregor Kofler

RobG meinte:
There is rarely any need to name a submit button

There is. Frequently. When your server-side script wants to know,
whether you hit "cancel" or "delete" or "save"...

Gregor
 
R

RobG

RobG meinte:


There is. Frequently. When your server-side script wants to know,
whether you hit "cancel" or "delete" or "save"...

I guess you mean where a form has multiple submit buttons to indicate
which of a number of actions to take when the form is submitted - the
name can be used to determine which button was used to submit it.

That's certainly one case where naming the button is useful, athough
the same functionality can be provided using a single submit button
and say checkboxes or radio buttons to indicate the action to take.
 
G

Gregor Kofler

RobG meinte:
I guess you mean where a form has multiple submit buttons to indicate
which of a number of actions to take when the form is submitted - the
name can be used to determine which button was used to submit it.

That's certainly one case where naming the button is useful, athough
the same functionality can be provided using a single submit button
and say checkboxes or radio buttons to indicate the action to take.

Agreed, but I wouldn't call that good usability.
"
I want to

[ ] cancel editing
[ ] save this record
[ ] delete this record

[ Go >> ]
"

When have you last seen such a form? (It makes sense for multiple
entries, though.)

Gregor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top