How to call Struts Action using JavaScript

Discussion in 'Java' started by AG, Mar 7, 2006.

  1. AG

    AG Guest

    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.
     
    AG, Mar 7, 2006
    #1
    1. Advertising

  2. AG

    Guest

    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;
    }
    }
     
    , Mar 8, 2006
    #2
    1. Advertising

  3. AG

    jiji Guest

    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
     
    jiji, Mar 8, 2006
    #3
  4. AG

    AG Guest

    I am getting "Object doesn't support this property or method"
     
    AG, Mar 8, 2006
    #4
  5. AG

    aj69433

    Joined:
    Sep 4, 2008
    Messages:
    2
    how to use struts action when using onchange
     
    aj69433, Sep 5, 2008
    #5
  6. AG

    06p204

    Joined:
    Aug 12, 2011
    Messages:
    1
    JavaScript action

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

    Hope this will help.
     
    06p204, Aug 12, 2011
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Bloggs
    Replies:
    1
    Views:
    800
    Sudsy
    Aug 3, 2003
  2. rjweytens
    Replies:
    6
    Views:
    16,107
    rjweytens
    Jun 25, 2004
  3. runescience

    Struts mapping action to action???

    runescience, Feb 6, 2006, in forum: Java
    Replies:
    3
    Views:
    1,833
    runescience
    Feb 7, 2006
  4. vyshu
    Replies:
    1
    Views:
    2,558
    Richard Senior
    Apr 27, 2007
  5. John
    Replies:
    0
    Views:
    888
Loading...

Share This Page