• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JavaScript submit() method

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've got a web page with three images on it. All three images call the form.submit() javascript method in the onClick event. They all submit the same form. Here's the problem; none of them work. If I replace them all with input submit button objects everything works fine. Is there some sort of conflict that I'm missing here. Thanks for any help you can provide.
 
Sheriff
Posts: 67749
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like a syntax issue to me.

Code?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
make sure nothing is named submit.

You should call it by

document.FormName.submit();

or

document.forms[0].submit();

Eric
 
Christopher Elkins
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for the delay in my response. Thank you both.

Eric, I tried what you said and it seems to be working now. There are three images that are used to submit the form and one of them was named 'submit'. Upon changing the name of this image everything works fine again.

Now let me see if I am correct in my thinking. The javascript submit() method looked for a submit element in the form. It found the image named submit and tried to treat it like a submit button; however, since it was just an image with the exact same javascript behind it the call failed stating that the object didn't support that method. So the only element that should be named submit in a form is the submit button itself?
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Easy way of looking at it: when you name a form element submit, it overwrites the submit() method.

Eric
 
Christopher Elkins
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Works for me. Thanks again. It's always good to get your advise from an author. ha ha
 
If you two don't stop this rough-housing somebody is going to end up crying. Sit down and read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic