Using Scripts for User Feedback

In this section:

In a previous section, you added code to your FanClub application that deletes the name of a fan from the fannames data source.

However, you did not add any code asking your end users whether they are really sure about deleting this fan name.

You could easily create a confirmation form that asked your end users, "Are you sure you want to delete this fan?" If they click Yes, you execute the code to delete the fan. If they click Cancel, you return to Update_Form with the data source unchanged.

However, this means your application must reconnect to the WebFOCUS Server to get the confirmation form, which has the potential to slow down your application.

Instead of using Maintain forms and the Maintain language to create this confirmation form, you are going to use JavaScript. JavaScript (as well as VBScript) is a mini-scripting language that is ideal for validating actions locally.

Note: You must have completed Creating an Update Form before you can do this section.

Top of page

Using JavaScript to Confirm a Deletion

How to:

What does the JavaScript function have to do?

  1. It has to ask end users whether they are sure about deleting the fan from the fannames data source.

    You do this using the JavaScript confirm function.

  2. If the end user answers Yes, the JavaScript function needs to perform the Maintain function DeleteFan. If the end user answers Cancel, the function simply returns to Update_Form.

    You test what the end user response was using an if test. You execute DeleteFan using the IWCTrigger function, an Information Builders-supplied function that executes Maintain code from JavaScript.

Procedure: How to Confirm a Deletion Using JavaScript
  1. Open the Event Handler editor for Update_Form and select the Click event for DeleteButton.
  2. Delete the code in the Event Handler editor.
  3. Click the JavaScript button .
  4. Enter the following syntax:
    if (confirm("Are you sure you want to delete this fan?"))
      alert("Delete cancelled!");

    Note: JavaScript is case-sensitive. Make sure you type this syntax exactly as shown.

  5. Close the Event Handler editor, deploy and run your application.