Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can't submit a form from javascript

 
sam White
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();


 
sam White
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much.
that works perfectly. I like the jQuery solution.
Sam
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic