Java Reference
In-Depth Information
Figure 15.3: An Ajax form with more than one submit button
This is a simple example, but as these page fragments become more
complex, you can imagine how much easier it is to use a ForwardResolu-
tion and a JSP rather than to return raw data and construct the page
fragment in JavaScript.
Handling Multiple Submit Buttons
We've been issuing Ajax requests as the user is typing characters into a
text field. Sometimes it's preferable to let the user finish entering values
and submit the form only when the user clicks a submit button, while
still using Ajax to send the request and handle the response.
Doing this with a form that has multiple submit buttons can be prob-
lematic if we're not careful. Consider the money example with a Send
and a Cancel button, as shown in Figure 15.3 .
When the form is serialized and posted, the default behavior is to in-
clude all inputs with their values, including all submit buttons no mat-
ter which one was clicked. Because Stripes relies on the parameter
name matching an event name to determine which event handler to
call, having all buttons present will wipe out the trail.
We can avoid this problem in a few ways. Prototype includes only one
submit button in the form submission if we specify it as a parameter to
form.serialize ( ):
Download ajax/web/WEB-INF/jsp/multiple_submits.jsp
function sendMoney(control) {
var form = control.form;
new Ajax.Updater('result', form.action,
{ method: 'post',
parameters: form.serialize({submit: control.name})
}
);
return false;
}
 
 
 
Search WWH ::




Custom Search