You can add JavaScript to click boxes, text entry boxes, and buttons in Adobe Captivate projects. The JavaScript can run when a user clicks inside or outside the box or button. Using JavaScript gives you the opportunity to extend projects in numerous ways while adding interactivity.
In this example, you will enter a name in a text entry box and click a button. If the name matches a pre-defined value, you will see a success message, else you will see a failure message.
-
Create a variable uName for the project. Do not assign any value to uName. For more information on creating a variable, see Create variables.
-
Insert a text entry box (Text > Text Entry Box) and assign the variable as a value in the text entry box. Highlight the text caption in the box and click [X] in the Properties Inspector. When you click [X], you can see a drop-down list from where choose the variable you had created and
insert the variable as text in the text entry box.This acts as a validation against any name other than the one you will set in the Advanced Actions panel.
-
Insert a button (Interactions > Button) near the text entry box. Select the button, click Actions in the Properties Inspector, and choose Execute JavaScript from the On Success drop-down list.
Also, clear the Continue Playing the Project
check-box to pause the slide after clicking the Submit button in the browser.
In the second example, you will use some in-built Captivate variables and view information, such
As shown in the previous procedure, create a button, and assign it to execute some JavaScript code upon a click event.
To display the current date in DD/MM/YYYY format, use the variable cpInfoCurrentDateStringDDMMYYYY. Enter the following JavaScript code in the code editor.
myDate=window.cpAPIInterface.getVariableValue("cpInfoCurrentDateStringDDMMYYYY"); alert(myDate);