Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to call Struts Action using JavaScript

Reply
Thread Tools

How to call Struts Action using JavaScript

 
 
AG
Guest
Posts: n/a
 
      03-07-2006
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.

 
Reply With Quote
 
 
 
 
tandem.young@gmail.com
Guest
Posts: n/a
 
      03-08-2006
I think you can do it like this:

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

....

<script language="javascript">

function doABC(sel) {
var form = document.forms[i];//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;
}
}

 
Reply With Quote
 
 
 
 
jiji
Guest
Posts: n/a
 
      03-08-2006
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

 
Reply With Quote
 
AG
Guest
Posts: n/a
 
      03-08-2006
I am getting "Object doesn't support this property or method"

 
Reply With Quote
 
aj69433 aj69433 is offline
Junior Member
Join Date: Sep 2008
Posts: 2
 
      09-05-2008
how to use struts action when using onchange
 
Reply With Quote
 
06p204 06p204 is offline
Junior Member
Join Date: Aug 2011
Posts: 1
 
      08-12-2011
Try something like that.
document.getElementById('myForm').doAction('<fmt:m essage key="My.action.name" bundle="${local}" />');

Hope this will help.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Struts: 1 action, 1 Form, several views handled by 1 only action. Any idea for better design? John Java 0 06-26-2007 11:22 PM
Can we call an Action from another Action in struts??? vyshu Java 1 04-27-2007 09:19 AM
Struts mapping action to action??? runescience Java 3 02-07-2006 04:07 PM
Struts Forward to an Action from an to Action and URLs rjweytens Java 6 06-25-2004 01:49 PM
Struts Static Action Form vs Dyanamic Action Form Joe Bloggs Java 1 08-03-2003 02:30 AM



Advertisments