Reputation: 189
I have a select tag. s:select
inside a form. I want to send a post request to the action. I have struts 2 json plugin in place. I am not any in javascript or jquery.
<s:form action="selectFileType" method="post"
id="selectFileTypeForm">
<div>
<s:select id="select" headerKey=""
headerValue="%{getText('uploadAttachmentType.please.select')}"
name="uploadAttachmentType" list="attachmentTypeList"
required="true"
onchange="this.form.submit();"></s:select>
<s:hidden id="declarationObj_ideclare"
name="declarationObj.ideclare" />
<s:hidden id="declarationObj_completingpersonname"
name="declarationObj.completingpersonname" />
<s:hidden id="declarationObj_completingpersonofficaltitle"
name="declarationObj.completingpersonofficaltitle" />
<s:hidden id="declarationObj_completingpersonphone"
name="declarationObj.completingpersonphone" />
<s:hidden id="declarationObj_completingpersonext"
name="declarationObj.completingpersonext" />
</div>
</s:form>
`
Upvotes: 0
Views: 1382
Reputation: 88
Struts 2 has not good tools to perform ajax but you can send post request using jQuery only.
At first you need to find a target element in source code of rendered page and to make selector. It should look something like select[name='searchEngine'] option:selected
.
Then you can write script that send value of your selected element to destination_url
. For example:
// get element value
var selectedItem = $("select[name='searchEngine'] option:selected").val();
// send post request
$.post("destination_url", {item: selectedItem}, function() {
alert("ok");
});
See an example there and read getting started guide there.
That's it.
Upvotes: 1