Difference between revisions of "Adding a Button that Runs a JavaScript"

From SmartWiki
Jump to: navigation, search
(See Also)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
If you wish to have a button on the page that runs a custom [[Browser Script]] use the following technique:
 
If you wish to have a button on the page that runs a custom [[Browser Script]] use the following technique:
  
1) Create a [[Custom Field Type: Display Only – Text or System Object|Display Only - Text or System Object Custom Field]]. In the '''Text/Link:''' section include the following:
+
1) Create a [[Custom Field Type: Display Only – Text or System Object|Display Only - Text or System Object]] or [[Custom Field Type: Read Only – System Variables|Read Only – System Variables]] Custom Field. In the '''Text/Link:''' section include the following:
 
  <input type="button" class=Button value="Button Label" onClick='runThisScript()'/>
 
  <input type="button" class=Button value="Button Label" onClick='runThisScript()'/>
  
Line 7: Line 7:
 
* '''Button Label''' is the label you wish to have on the button
 
* '''Button Label''' is the label you wish to have on the button
 
:and
 
:and
* '''runThisScript()''' is the function you have defined separate in a [[Browser Script]] (step 2).
+
* '''runThisScript()''' is the function you have defined separately in a [[Browser Script]] (step 2).
  
  
Line 18: Line 18:
 
</pre>
 
</pre>
  
 
+
==See Also==
 +
* [[Use a Button to Create a Level 1]]
 +
* [[Use a Button to Create a Level 2]]
  
 
[[Category: Custom Fields]][[Category: JavaScript]]
 
[[Category: Custom Fields]][[Category: JavaScript]]

Latest revision as of 10:06, 13 January 2014

If you wish to have a button on the page that runs a custom Browser Script use the following technique:

1) Create a Display Only - Text or System Object or Read Only – System Variables Custom Field. In the Text/Link: section include the following:

<input type="button" class=Button value="Button Label" onClick='runThisScript()'/>

where:

  • Button Label is the label you wish to have on the button
and
  • runThisScript() is the function you have defined separately in a Browser Script (step 2).


2) Create a Browser Script Custom Field that includes the JavaScript function you wish to run when the button is clicked:

function runThisScript()
{
// enter whatever the script should do here
}

See Also