fatherazrael
fatherazrael

Reputation: 5977

How to send Submit Button name as parameter; on form submit using JQuery/Spring MVC?

When user click submit button; following method of Javacode need to executed having params ''endActivity''(which is name of Submit Button)

Java Code:

@Loggable
@RequestMapping(value = "save/permanent", method = RequestMethod.POST, params = { "endActivity" })
public String finalize(@ModelAttribute("MyForm") MyForm form, BindingResult br, WebRequest wr, RedirectAttributes attr) {

In HTML, When we give input as type submit with name endActivity, The above method gets called successfully

<input type="submit" name="endActivity" /> ; 

Now we need to change button type from Submit to Button; as per our new requirement. So new HTML is given below:

<inupt type="button" name="endActivity12" /> ; 

In JQuery; on click of button; a confirmation dialog appears with value Yes and No; on click of YES button; following script is called for dynamic submission:

$('#formName').append($('<input>').attr('type', 'hidden').attr('name', 'endActivity').val('endActivity')).submit();

but Java code is not getting executed on same which means it is not getting Parameter. Can anyone help me in resolving the issue?

Upvotes: 2

Views: 1220

Answers (1)

NightsWatch
NightsWatch

Reputation: 467

Adding the hidden element in the form, assign name of button and submit the form to controller work for this.

Upvotes: 2

Related Questions