Examples: JavaScript events

  1. This form onLoad event sets the value of the Status field to "open" when a document loads. It works in a browser and the Notes client.
    document.forms[0].Status.value = "open"
  2. This version of the onLoad event solicits a value for the Status field.
    reply = prompt("Status = 'Open' or 'Closed'?", "Open")
    while (reply != "Open" && reply != "Closed") {
        reply = prompt("Enter 'Open' or 'Closed'", "Open")
    }
    document.forms[0].Status.value = reply
  3. This Status field onBlur event prevents the user from exiting the field without entering "Open" or "Closed." It works in a browser and the Notes client.
    r = document.forms[0].Status.value
    while (r != "Open" && r != "Closed") {
        r = prompt("Status must be 'Open' or 'Closed'", "Open")
    }
    document.forms[0].Status.value = r
  4. The code shown in the last example could be placed instead in the onSubmit event. An action or hotspot containing the following @commands activates the code.
    @Command([FileSave]);
    @Command([FileCloseWindow])
  5. This function is placed in the JSHeader event of a form.
    function testEvent(eventName) {
        alert("This is the " + eventName + " event")
    }

    The function executes whenever another event on the form (including a field, action, or hotspot) calls it, for example:

    TestEvent("onLoad")