Examples: JavaScript in HTML

  1. This is text on a form marked as passthru HTML. It prompts for a name and puts it in the LoginName field. The text must follow the LoginName field on the form.
    <SCRIPT LANGUAGE="JavaScript">
        n = prompt("Domino login name?", "Anonymous")
        document.forms[0].LoginName.value = n
    </SCRIPT>
  2. This passthru text uses an anchor tag to put JavaScript in a URL using the "javascript:" protocol.
    <A HREF="javascript:alert('You are Anonymous unless you supply a login name')">Read me</A>
  3. This passthru text contains the user name as a computed value. The computed value is inserted by choosing Create - Computed Text and specifying "@UserName" for the formula.
    <SCRIPT LANGUAGE=JavaScript>
        alert("Your user name is <Computed Value>")
    </SCRIPT>
  4. This LotusScript agent terminates by sending JavaScript to the browser. The JavaScript displays a message and then loads the "Main View."
    Sub Initialize
        Dim s As New NotesSession
        Dim db As NotesDatabase
        Dim dc As NotesDocumentCollection
        Dim doc As NotesDocument
        Dim arg As String, p1 As Long
        arg = s.DocumentContext.Query_String(0)
        p1 = Instr(arg, "&")
        If p1 = 0 Then
            Print "Need argument 'Open' or 'Closed'"
            Exit Sub
        Else
            arg = Lcase(Mid$(arg, p1 + 1))
            If arg <> "open" And arg <> "closed" Then
                Print "Argument must be 'Open' or 'Closed'"
                Exit Sub
            End If
        End If
        arg = Ucase(Left$(arg, 1)) + Right$(arg, Len(arg) - 1)
        Set db = s.CurrentDatabase
        Set dc = db.UnprocessedDocuments
        Set doc = dc.GetFirstDocument
        Do While Not(doc Is Nothing)
            doc.Status = arg
            Call doc.Save(False, True)
            Set doc = dc.GetNextDocument(doc)
        Loop
        Print "<SCRIPT LANGUAGE=JavaScript>"
        Print "alert(""Status changed to '" & arg & _
              "' in all documents"")"
        Print "location.href = ""/Web+test.nsf/Main+View?OpenView"""
        Print "</SCRIPT>"
    End Sub
    Sub Initialize
        Dim s As New NotesSession
        Dim db As NotesDatabase
        Dim dc As NotesDocumentCollection
        Dim doc As NotesDocument
        Dim context As NotesDocument
        Dim arg As String
        Set context = s.DocumentContext
        arg = s.DocumentContext.Query_String(0)
        p1 = Instr(arg, "&")
        If p1 = 0 Then
            Print "Need argument 'open' or 'closed'"
        Else
            arg = Lcase(Mid$(arg, p1 + 1))
            If arg <> "open" And arg <> "closed" Then
                Print "Argument must be 'open' or 'closed'"
            End If
        End If
        Set db = s.CurrentDatabase
        Set dc = db.UnprocessedDocuments
        Set doc = dc.GetFirstDocument
        Do While Not(doc Is Nothing)
            doc.Status = arg
            Call doc.Save(False, True)
            Set doc = dc.GetNextDocument(doc)
        Loop
        Print "<SCRIPT LANGUAGE=JavaScript>"
        Print "alert(""Status changed to '" & arg & _
              "' in all documents"")"
        Print "location.href = ""/Web+test.nsf/Main+View?OpenView"""
        Print "</SCRIPT>"
    End Sub