1

I have a JS function that I want to run (call an asynchronous JMS queue function) upon submitting.

Can someone point me to an example of how to do that from inside a Spring form? I know how to do a $(document).ready(function(), but I only want to do this when POSTing a form submission.

2
  • 1
    I should add that I tried the onSubmit(), but that doesn't appear to fire inside a Spring form. Commented May 14, 2013 at 17:04
  • 2
    Can you include the code you've tried? Or, can you create a jsFiddle example of your problem? Commented May 14, 2013 at 17:08

1 Answer 1

3

Attaching a submit handler with jQuery:

HTML:

<form id="form1" action="#" method="POST">
   <input type="text" name="field1" />
   <input type="submit" />
</form>

JavaScript:

$(document).ready(function() {
  $('#form1').submit(function() {
    alert('Handler for .submit() called.');
  });
});

Regarding your use of Spring, the Spring form tag will generate a usual HTML form. You can specify an id (or class) for it and attach a handler with jQuery. Link to an example: http://jsfiddle.net/kolchytsky/Wy47g/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.