Search code examples
jquerystruts2-jquerystruts2-json-pluginstruts2struts2-jquery-grid

Struts2 Jquery conformation


I'm using struts2-jquery plugin in my application, i'm using its sj:a component to submit forms.

Here is my code.

 <s:iterator value="countryList" var="country">
     <s:form id="frm%{countryID}"  action="add_country_save">
        <s:textfield name="country.countryName" size="40" id="txt%{countryID}"/>
</s:form>

<sj:a id="ah%{countryID}" formIds="frm%{countryID}"
 targets="add_country" button="true" > Delete </sj:a>

 </s:iterator>

Everything works fine until a requirement came up that I've to display a confirmation dialog before submitting a form .

This is what actually i have tried to implement.

If user click Ok,the form submission will be submitted. If user click cancel,the form submission will be canceled.

If any one had a solution please share with me.

Thank's


Solution

  • You've specified that ids are generated by the server side,therefore you cannot easily select their id because it will vary from different results on your database.

    The simplest way to achieve your goal is this.

    <form onsubmit="return confirm('Do You Want to Submit the Form?');">
    

    if you have multiple forms, I would suggest to add a name attribute in your form.

    <s:form id="frm%{countryID}" name ="myform" action="add_country_save">
         <s:textfield name="country.countryName" size="40" id="txt%{countryID}"/>
    

    And attach an event handler to all of the forms that has that name attribute.

    $('form[name ="myform"]').click(function(){
         if(confirm('Do you want to submit the form?')){
            $(this).submit();
         }
     });