|
::Features
::Download
::Tutorial
::Examples
::Documentation ::FormBuilder Google Group ::Old List Archives ::Contribute |
|
Intermediate Tutorial - Step 8: JavaScript Actions 2
We saw earlier how JavaScript actions could be attached to fields by
using
In our preceding example, we wanted to change how we validate the form depending on what submit button was clicked. It would be nice if we could skip validation entirely if the user hits "Cancel", and it would also be nice to pop up a special confirmation box if the user hits "Delete", to prevent accidents. No problem:
$form = CGI::FormBuilder->new(
method => 'post',
fields => \@fields,
submit => [qw/Update Delete Cancel/],
reset => 0, # turn off reset button
jsfunc => <<EOJS
if (form._submit.value == "Delete") {
if (confirm("Really DELETE this entry?")) return true;
return false;
} else if (form._submit.value == "Cancel") {
return true;
}
EOJS
);
The value of the submit button is held in the special field
form._submit.value. If the user clicks "Delete",
then a dialog box will pop up, asking them to confirm their
selection. If they hit "Ok", then it will return true (skipping
validation). Otherwise, it will return false (failing validation).
If the user hits "Cancel", then it will again
The |
| FormBuilder is © Nate Wiger, with contributions from many people. |