How to call Struts Action using JavaScript

A

AG

My web page has a drop down box, and I want to call struts action as
soon as the value changes from the drop down.
(Basically submit a form using JavaScript on "onchange" event of
dropdown)

Can someone give me a direction for such JavaScript?

example would be

JSP
<html:form action="/someAction" method="POST">

Struts-config.xml
<action path="/someAction" type="com.SomeAction" name="someForm"
parameter="action" scope="request" input="someinput">
<forward name="someLocalActn"
path="/someAction?action=display"></forward>
</action>

Thanks.
 
T

tandem.young

I think you can do it like this:

<html:select onclick="javascript:doABC(this);">
....

....

<script language="javascript">

function doABC(sel) {
var form = document.forms;//here i depends on which form you want
to submit.
//or you can define it in
the case sentence.
switch(sel.value) {
case "A":
form.action = "...";
form.submit();
break;
case "B":
form.action = "...";
form.submit();
break;
case "C":
form.action = "...";
form.submit();
break;
}
}
 
J

jiji

I think u are trying to use DispatchAction.. here is the code for

<!-- html -->
<form action="/someAction">
<input type="hidden" name="action" />
<select name="selectname" onchange="javascript:submitform(this)">
<option>option1</option>
<option>option2</option>
<option>option3</option>
</select>
</form>
<script>
function submitform(sel) {
document.someForm.action=sel.value;
document.someForm.submit();
}

</script>

Struts-config.xml
<action path="/someAction"
type="com.SomeAction"
name="someForm"
parameter="action"
scope="request"
input="someinput">
<forward name="someLocalActn" path="/someAction?action=display"/>
</action>

I hope this will work.. let me know if im wrong
 
Joined
Aug 12, 2011
Messages
1
Reaction score
0
JavaScript action

Try something like that.
document.getElementById('myForm').doAction('<fmt:message key="My.action.name" bundle="${local}" />');

Hope this will help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top