JavaScript CookBook/Custom Scripts/Adding Inline Javascript to Form Actions

From GeoMedia Smart Client
Jump to: navigation, search
GMSC 2013/2014 Javascript API Overview Form Events Types Utility Functions client-side Validation Conditions Interaction with SmartClient Cookbook Cheatsheet

Adding Inline Javascript to Form Actions

Problem: You want to execute some Javascript code every time a <FormAction> button gets clicked.

Solution: Use the action attribute of the <FormAction> to include the javascript code.

<FormAction name="SimpleJSButton" label="A Simple Javascript Button" action="SCRIPT[alert('I appear each time this button is clicked')]" /></FormField>

Some useful hints:

  • you have to make sure that all Javascript functions you plan to call are available on the page - you probably have to include them via a custom script (see recipe below).
  • use single quotation marks (') for strings in order to avoid XML validation errors (since double quotes are used to delimit the action attribute)
  • you can use the semicolon (;) to combine two statements inside one script action (e.g. SCRIPT[alert('first alert');alert('second alert')]), however this does NOT guarantee execution order in case of async operations (e.g. AJAX requests) - see Backend Interaction for a solution on this problem.



Other Recipes in this category: