0

I have a form and once it gets submitted successfully , then after the roundtrip from the server I get a success message displayed on the same page.

I am using the following code:

<s:if test="%{#session.str==1}" >
<div onload="showSuccessToast();">
  <button onclick="showSuccessToast();"></button>
</div>
</s:if>

Now when I return from the server (form submit successful) then the button is displayed and on its onClick event the showSuccessToast() is called but when I expect div to call this function on the onload event it has no effect.

Any idea how to achieve this.

Prateek
  • 3,923
  • 6
  • 41
  • 79

1 Answers1

2

Modify it as follows which is kind of simulating "on-load-div":

<s:if test="%{#session.str==1}" >
<div>
  <button onclick="showSuccessToast();"></button>
  <script language="javascript" type="text/javascript">
      showSuccessToast();
  </script>
</div>
</s:if>
Vikdor
  • 23,934
  • 10
  • 61
  • 84
  • I have got one more problem , when I reload the page the form gets automatically submitted as the form-action is called. Any fix for this. – Prateek Aug 27 '12 at 09:36
  • Irrespective of the server-side technology (jsp/asp/php etc.,), the client side javascript code would be the same. These links are a good resource on ajax form submit: http://api.jquery.com/submit/, http://stackoverflow.com/questions/3638750/jquery-form-submit – Vikdor Aug 27 '12 at 09:37