Depending on what your js function does, you may also be able to use the notifyTopics/listenTopics event mechanisms. Look at the example in "Preventing a Request" at http://struts.apache.org/2.x/docs/ajax-tags.html#AjaxTags-preventingRequest

Otherwise try the handler="" attribute to call your own js function before making the request yourself (I haven't tried this though and can't point to any examples)

Mansour wrote:
OK I found my problem. I shouldn't add onClick event to the anchor, but what do I do to execute a js function when this anchor is clicked. I tried using onMouseDown, but the same results.


Mansour wrote:
Thank you. That helped but still can not submit a form using an anchor out side that form. The fields are not populated in the action.

The code on the Site :

Using the anchor tag to submit a form:

<s:form id="form1">
 <input type="textbox" name="data">   </s:form>

<s:url id="ajaxTest" value="/AjaxTest.action" />

<s:a theme="ajax" href="%{ajaxTest}" formId="form1">Submit form</s:a>




My code:

<s:head theme="ajax"></s:head>

<table>
    <tr>

        <td>
<s:a href="javascript://" onclick="changeState(true);">edit</s:a>
        <td>
<s:url id="ajaxSubmit" value="/updateAccount.action"></s:url> <s:a theme="ajax" href="%{ajaxSubmit}" formId="MyData" onclick="changeState(false);"> save </s:a>
        </td>
    </tr>
</table>



<table id="data_table">
    <s:form id="MyData">
        <tr>
            <td><s:label value="AccId:" /></td>
            <td><s:property value="acc.id" /> <s:hidden name="acc.id"
                value="%{acc.id}" id="acc.id" /></td>
        </tr>

        <tr>
            <td><s:label value="First Name" /></td>
<td><s:textfield name="acc.firstName" disabled="true" value="${acc.firstName}" /></td>
        </tr>

</s:form>
</table>


That's not a big deal as I can move the anchors inside the form, but may be I am missing something here.




Jeromy Evans wrote:
Ensure you've included <s:head theme="ajax"> to include the required javascript and try turning on ajax debugging (<s:head theme="ajax" debug="true">). Ensure the javascript exists in your html.
See the top of http://struts.apache.org/2.x/docs/ajax-tags.html

Mansour wrote:
I am populating some fields that can be edited and saved. Trying to do this using ajax. The action is getting called but the form is never submitted, and the updated data is lost.


<table id="data_table" >
<s:form id="MyData" action="updateAccount" >
   <tr>
       <td>
           <s:label value="AccId:"  />
       </td>
       <td>
           <s:property value="acc.id"    />
           <s:hidden name="acc.id" value="%{acc.id}" id="acc.id" />
       </td>
   </tr>

   <tr>
       <td><s:label value="First Name"  /></td>
<td><s:textfield name="acc.firstName" value="${acc.firstName}" /></td>
   </tr>
</td>

</table>

<s:url id="ajaxSubmit" value="/updateAccount.action" />
<s:a theme="ajax" href="%{ajaxSubmit}" formId="MyData"> save </s:a>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to