- Hide the Get Details buttons.
- Show the Save button.
- Set the editability of the Customer Details fields.
- Inform the user if there was no match.
Acrobat offers a selection of objects that can contains Javascript. Document Javascripts - Tools, Forms, Document Javascripts - contain global functions, variables and code that is to be run when the document is opened. Page Javascripts - Document, Set Page Action - determine what functions to run whenever the current page is opened or closed within the viewer. Each field can also have its own Javascripts that run when certain actions or situations occur.
One of these is the Calculation script that will be run whenever the field they are attached to is refreshed - either by the document being opened, by a user scrolling onto a page containing the field etc. We will use this type of script in conjunction with a hidden field on the Form which contains the return value from our ASP page indicating if we had a successful match, thus whenever that value is changed it will run the recalculate script. The actual Javascript that we will use is as follows :
var status=this.getField("retval");
// if the value is one, then we got a record
if (status.value=="1")
{
// hide the Retrieve button and show the Save one
var saveButton=this.getField("savebtn");
saveButton.hidden=false;
var getButton=this.getField("submitbtn");
getButton.hidden=true;
// set the Customer Name to be Read Only
var orderNo=this.getField("orderno");
orderNo.readonly=true;
}
// else inform the user
else
{
app.alert("No matching records were found.",0,0);
}
// reset the status value
status.value="0";
In the final section of this article, we review what has been covered and provide some links to books and websites for futher study.