tags:

views:

298

answers:

1

Hi All,

   I am facing an issue while handling multiple buttons in a form using struts.

I have three buttons add,delete and go .I have made forward as hidden and on click of a button i would get the name of the button. The problem is with go button on click of that i want to call a javascript and then call the action and return to the same page .

Question is i am facing issue whicl calling javascript on click of a button and returning to the same page.Please tell me a proper way to handle multiple buttons in a form and its action

A: 

Well, you can implement onclick with a javascript call, and within the javascript do the real submit.

What I do is:

javascript:

function submitMyForm() {
  var theForm = document.forms['formname'];
  // sometimes re-write the action
  // theForm.action = '<html:rewrite page="somepage.do"/>';

  theForm.submit();
}

HTML / JSP / struts

<html:submit value="Save" onclick="submitMyForm(); return false;"/>

Hope that answers some of the question.

Getting back to the same page is to either having the form submit to that page, or submit to another controller which directs back to your page.

extraneon
can we use location.href="some action "and then submit ?My problem is on click of go i need just to perform go action not other button actions.
sarah
@sarah I don't understand your problem. It's a button. If you click that action get's executed. In this case it's a form submit with optionally submitting to a different page. The other buttons don't come into the question at all.If you have more than 1 submit button, all of which do different thins on the same form, consider creating a hidden field and call submitMyForm(paramvalue), and fill the hidden field in the javascript with paramvalue
extraneon