How to Use OnFocusScript and OnBlurScript Properties
Both the OnBlurScript and OnFocusScript properties (used with the FieldInfo object) will set or retrieve a script to execute, but they use different triggers.
- OnBlurScript
When the focus moves from the specified field to another location, OnBlurScript sets or retrieves the script to execute. - OnFocusScript
When the focus moves from another location to the specified field, OnFocusScript sets or retrieves the script to execute.
Code Example for OnFocusScript and OnBlurScript
The following example includes a Click Here button:
- click on the button once and OnFocusScript is called.
- click any where off the button and OnBlurScript is called.
'==========================================================
Dim FSO, strPath, outputFile, inputFile
Dim intOpenOutputFile, intOpenInputFile, intResult
' Get current path
Set FSO = CreateObject("Scripting.FileSystemObject")
strPath = FSO.GetFile(Wscript.ScriptFullName).ParentFolder & "\"
Set FSO = Nothing
Set oTK = CreateObject("APToolkit.Object")
outputFile = strPath & "output.pdf"
inputFile = strPath & "OnBlurOnFocusSample.pdf"
' Create the new PDF file
intOpenOutputFile = oTK.OpenOutputFile(outputFile)
If intOpenOutputFile <> 0 Then
ErrorHandler "OpenOutputFile", intOpenOutputFile
End If
' Create the new PDF file
intOpenInputFile = oTK.OpenInputFile(inputFile)
If intOpenInputFile <> 0 Then
ErrorHandler "OpenInputFile", intOpenInputFile
End If
totFields = oTK.CountFormFields
Set aFI = oTK.FieldInfo("btnTest", 1)
aFI.OnFocusScript = "myField=this.getField(""txtResult"");myField.value = " & cstr(totFields) & " +"" this is OnFocusScript\n"";"
aFI.OnBlurScript = "myField=this.getField(""txtResult"");myField.value = """" +"" this is OnBlurScript\n"";"
intResult = oTK.CopyForm(0, 0)
If intResult <> 1 Then
ErrorHandler "CopyForm", intResult
End If
'==========================================================
'***********************************************************************
' Close Files, Dispose TK Object
'***********************************************************************
' Close the files
oTK.CloseOutputFile
' Release Object
Set oTK = Nothing
' Process Complete
msgbox "Done!"
'==========================================================
'***********************************************************************
' Error Handling
'***********************************************************************
Sub ErrorHandler(method, outputCode)
msgbox("Error in " & method & ": " & outputCode)
End Sub
'==========================================================