DynaPDF.CreateJSAction
----------------------

Creates a JavaScript action.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [DynaPDF](component_DynaPDF.md) | [6.4](newinversion64.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "DynaPDF.CreateJSAction"; PDF; Script ) 

**MBS**( **"DynaPDF.CreateJSAction";** /\* Creates a JavaScript action. \*/  
**$PDF**; /\* The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). \*/   
**$Script**) /\* The javascript text. \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| PDF | The PDF reference returned from [DynaPDF.New](DynaPDFNew.md). | $pdf |
| Script | The javascript text. |  |

### Result

Returns number or error.

### Description

Creates a JavaScript action.   
A JavaScript Action causes a script to be compiled and executed by the JavaScript interpreter of Adobe's Acrobat. Depending on the nature of the scripts, this can cause various interactive form fields in the document to update their values or change their visual appearances.   
The parameter Script must be a valid JavaScript. The script is not checked by DynaPDF whether it is valid or not. Note that older Acrobat versions of Adobe's Acrobat do not support all [JavaScript](component_JavaScript.md) functions. Due to several bugs in Acrobat 4/5 an invalid JavaScript can cause an access violation in Adobe's Acrobat. Test your scripts carefully with all Acrobat versions which must be supported.   
See also [CreateJSAction](https://www.monkeybreadsoftware.com/DynaPDF-Manual/CreateJSAction.shtml) function in DynaPDF manual.

### Examples

Create sum field:

 Set Variable \[$y ; Value:50\]  
Set Variable \[$script ; Value:"var v1 = this.getField(\\"Val1\\");" &amp; ¶ &amp; "var v2 = this.getField(\\"Val2\\");" &amp; ¶ &amp; "var v3 = this.getField(\\"Val3\\");" &amp; ¶ &amp; "event.value = v1.value + v2.value + v3.value;"\]  
Set Variable \[$script ; Value:MBS ( "[Text.ReplaceNewLine](TextReplaceNewLine.md)"; $script ; 2)\]  
Set Variable \[$a ; Value:MBS ( "DynaPDF.CreateJSAction"; $pdf ; $script )\]  
\#Create 1st field   
Set Variable \[$f ; Value:MBS ( "[DynaPDF.CreateTextField](DynaPDFCreateTextField.md)"; $pdf ; "Val1"; -1; 0; 0; 50; $y ; 200; 20)\]  
Set Variable \[$r ; Value:MBS ( "[DynaPDF.SetTextFieldValue](DynaPDFSetTextFieldValue.md)"; $pdf ; $f ; "50.00 "; "50.00 "; "Right")\]  
Set Variable \[$r ; Value:MBS ( "[DynaPDF.SetNumberFormat](DynaPDFSetNumberFormat.md)"; $pdf ; $f ; "NoneDot"; 2; "MinusBlack")\]  
\#Create 2nd field   
Set Variable \[$y ; Value:$y + 30\]  
Set Variable \[$f ; Value:MBS ( "[DynaPDF.CreateTextField](DynaPDFCreateTextField.md)"; $pdf ; "Val2"; -1; 0; 0; 50; $y ; 200; 20)\]  
Set Variable \[$r ; Value:MBS ( "[DynaPDF.SetTextFieldValue](DynaPDFSetTextFieldValue.md)"; $pdf ; $f ; "100.00 "; "100.00 "; "Right")\]  
Set Variable \[$r ; Value:MBS ( "[DynaPDF.SetNumberFormat](DynaPDFSetNumberFormat.md)"; $pdf ; $f ; "NoneDot"; 2; "MinusBlack")\]  
\#Create 3rd field   
Set Variable \[$y ; Value:$y + 30\]  
Set Variable \[$f ; Value:MBS ( "[DynaPDF.CreateTextField](DynaPDFCreateTextField.md)"; $pdf ; "Val3"; -1; 0; 0; 50; $y ; 200; 20)\]  
Set Variable \[$r ; Value:MBS ( "[DynaPDF.SetTextFieldValue](DynaPDFSetTextFieldValue.md)"; $pdf ; $f ; "200.00 "; "200.00 "; "Right")\]  
Set Variable \[$r ; Value:MBS ( "[DynaPDF.SetNumberFormat](DynaPDFSetNumberFormat.md)"; $pdf ; $f ; "NoneDot"; 2; "MinusBlack")\]  
\#Create sum field   
\#This last field calculates sum of other fields   
\#Works only in PDF Viewers supporting JavaScript!   
Set Variable \[$y ; Value:$y + 30\]  
Set Variable \[$f ; Value:MBS ( "[DynaPDF.CreateTextField](DynaPDFCreateTextField.md)"; $pdf ; "Sum"; -1; 0; 10; 50; $y ; 200; 20)\]  
Set Variable \[$r ; Value:MBS ( "[DynaPDF.SetFieldBorderWidth](DynaPDFSetFieldBorderWidth.md)"; $pdf ; $f ; 0)\]  
Set Variable \[$r ; Value:MBS ( "[DynaPDF.SetTextFieldValue](DynaPDFSetTextFieldValue.md)"; $pdf ; $f ; "350.00 €"; "350.00 €"; "Right")\]  
Set Variable \[$r ; Value:MBS ( "[DynaPDF.SetFieldFlags](DynaPDFSetFieldFlags.md)"; $pdf ; $f ; "ReadOnly"; 0)\]  
Set Variable \[$r ; Value:MBS ( "[DynaPDF.AddActionToObj](DynaPDFAddActionToObj.md)"; $pdf ; "Field"; "OnCalc"; $a ; $f )\]  
Set Variable \[$r ; Value:MBS ( "[DynaPDF.SetNumberFormat](DynaPDFSetNumberFormat.md)"; $pdf ; $f ; "CommaDot"; 2; "MinusBlack"; " €"; 0)\]  
Create checkbox to confirm page and jump to next one:

 Set Variable \[ $f ; Value: MBS ( "[DynaPDF.CreateCheckBox](DynaPDFCreateCheckBox.md)"; $pdf ; "OK"; "OK";0; -1; $PageWidth -150; $pageHeight -20; 15; 15 ) \]   
\# This is javascript from Adobe to go to next page You could substitute many of their examples   
Set Variable \[ $script ; Value: "this.pageNum++" \]   
Set Variable \[ $script ; Value: MBS ( "[Text.ReplaceNewLine](TextReplaceNewLine.md)"; $script ; 2 ) \]   
Set Variable \[ $a ; Value: MBS ( "DynaPDF.CreateJSAction"; $pdf ; $script ) \]   
Set Variable \[ $r ; Value: MBS ( "[DynaPDF.AddActionToObj](DynaPDFAddActionToObj.md)"; $pdf ; "Field"; "OnMouseUp"; $a ; $f ) \]  
### See also

- [DynaPDF.CreateCheckBox](DynaPDFCreateCheckBox.md)
- [DynaPDF.CreateGoToAction](DynaPDFCreateGoToAction.md)
- [DynaPDF.CreateGoToActionEx](DynaPDFCreateGoToActionEx.md)
- [DynaPDF.CreateListBox](DynaPDFCreateListBox.md)
- [DynaPDF.CreateResetAction](DynaPDFCreateResetAction.md)
- [DynaPDF.CreateSubmitAction](DynaPDFCreateSubmitAction.md)
- [DynaPDF.CreateURIAction](DynaPDFCreateURIAction.md)
- [DynaPDF.SetFieldFlags](DynaPDFSetFieldFlags.md)
- [DynaPDF.SetNumberFormat](DynaPDFSetNumberFormat.md)
- [DynaPDF.SetTextFieldValue](DynaPDFSetTextFieldValue.md)

### Example Databases

- [DynaPDF/Add Weblinks](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Add%20Weblinks.shtml#3ScriptAnchor_)
- [DynaPDF/Create PDF with sum form field](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/DynaPDF/Create%20PDF%20with%20sum%20form%20field.shtml#2ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Plugin, version 6.4pr5](https://www.mbsplugins.de/archive/2016-08-29/MBS_FileMaker_Plugin_version_6/monkeybreadsoftware_blog_filemaker)
- [Tip of the day: DynaPDF form creation with calculation with FileMaker](https://www.mbsplugins.de/archive/2016-08-24/Tip_of_the_day_DynaPDF_form_cr/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 24th August 2016 , last changed 21st May 2017

  
[DynaPDF.CreateICCBasedColorSpaceContainer](DynaPDFCreateICCBasedColorSpaceContainer.md) - [DynaPDF.CreateListBox](DynaPDFCreateListBox.md)

[HTML Version](DynaPDFCreateJSAction.shtml)