how to validate with two different submit in struts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kaleeswaran
    New Member
    • Mar 2007
    • 132

    how to validate with two different submit in struts

    hi!
    i am validating my form.the form has two different submit button like "SAVE" and "UPDATE" button.but i don't know how to different validatation while i clicking save button and update button.how to differentiate the function calling...?
    thank you,
    kaleeswaran
  • jamieg99
    New Member
    • Dec 2007
    • 3

    #2
    Originally posted by kaleeswaran
    hi!
    i am validating my form.the form has two different submit button like "SAVE" and "UPDATE" button.but i don't know how to different validatation while i clicking save button and update button.how to differentiate the function calling...?
    thank you,
    kaleeswaran
    You could change the action with javascript to point to different validating actions depending on what you click

    struts-config:

    <form path=/ValidateUpdate" validate="true" type="myClass" name="myForm" scope="request"/>
    <form path=/ValidateSave" validate="true" type="myClass" name="myForm" scope="request"/>


    jsp:

    <html:form onsubmit="retur n getAction(this) " method="post" action="/ValidateSave">
    <html:hidden name="myForm" property="submi tValue"/>
    <html:button onclick="setSub mitValue('save' )" name="myForm" property="save" value="save"/>
    <html:button onclick="setSub mitValue('updat e')" name="myForm" property="updat e" value="update"/>
    </html:form>

    js

    function getAction(f){
    var submitVal = document.getEle mentById("submi tValue").value;
    if(submitVal==' update')
    f.action.value = "/ValidateUpdate. do";
    else
    f.action.value = "/ValidateSave.do ";
    return true;

    }

    function setSubmitValue( val){
    document.getEle mentById("submi tValue").value = val;
    }

    Comment

    Working...