Two Laptop Bag*
The moose likes HTML, CSS and JavaScript and the fly likes Can't submit a form from javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Can Watch "Can New topic
Author

Can't submit a form from javascript

sam White
Ranch Hand

Joined: Feb 18, 2011
Posts: 208
Hi, With sprng mvc 3.0 and jsp, I want to submit a form from a javascript, but there there is no action.

Here is my form:


Javascript:



Any suggestion is very appreciated.
Thanks
Sam
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

Firstly, please be sure to use code tags, not quote tags for code. I have changed your post for you. it would also help if your indentation was proper.

Have you run the code in a JavaScript debugger? All modern browsers have a built-in debugger, except for Firefox which has the Firebug plugin.

This fragment:

this.document.forms['delete_delivery'].submit();

even if it works (and likely does not -- what's up with the "this"?), is an antiquated and obsolete way of addressing elements. You should be using document.getElementById():

document.getElementById('delete_delivery').submit();

Or, do yourself a big favor and use jQuery to make your JavaScript much tidier and compact.

$('#delete_delivery').submit();



[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sam White
Ranch Hand

Joined: Feb 18, 2011
Posts: 208
thank you very much.
that works perfectly. I like the jQuery solution.
Sam
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

sam White wrote:thank you very much.
that works perfectly. I like the jQuery solution.

Me too!

And when you get to things like event handling and Ajax, jQuery is even a bigger win.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can't submit a form from javascript