I want to use the following anchor to submit a form with jquery to Spring. How is this done?
<a target="" title="" class="" href="">Save</a>
I've tried this, where requestNew is my form:
$(document).ready(function(){
$("a").click(function(){
$("#requestNew").submit(function(){
$.post("../acctRequests", $("#requestNew").serialize());
});
});
});
It doesn't seem to go anywhere.
You can use href=”#top” or href=”#” to link to the top of the current page. To use the anchor tag as submit button, we need the help of JavaScript. To submit the form, we use JavaScript . submit() function.
jQuery submit() Forms can be submitted either by clicking on the submit button or by pressing the enter button on the keyboard when that certain form elements have focus. When the submit event occurs, the submit() method attaches a function with it to run. It triggers the submit event for selected elements.
The <form> tag is used to create an HTML form for user input. The <form> element can contain one or more of the following form elements: <input> <textarea>
In the body tag, created an HTML form and specify the id, method, and action of the form. In the form, specify an anchor tag with an event onclick. Create a function for JavaScript that will get executed when the link is clicked. When we click on the link, the function submitForm() will get executed.
You are adding a new event handler; all you need to do is trigger the existing ones, and the browser's native functionality:
$(document).ready(function(){
$("a").click(function(){
$("#requestNew").submit();
});
});
Please use this
<a href="javascript:document.YOUR_FORM_NAME.submit()"> Submit</a>
<form name="YOUR_FORM_NAME" action="YOUR_ACTION_PAGE_URL" method=POST>
<input type="text" name="YOUR_INPUT_NAME" value="YOUR_INPUT_VALUE"/>
</form>
Replace "YOUR_ACTION_PAGE_URL" with your targeted action url
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With