<scriptblock>

NEW TO VERSION 4.2

This tag allows you to register a block of client-side script with the page hosting the XMod form.

 

ATTRIBUTES:

scriptid

This is an identifier for your block of script that uniquely identifies it within the hosting page - across modules. It is used when registering your script block and is required in order to prevent the block from being inserted more than once in the page. This textual value can be virtually anything you want. (Required) (String Value)

blocktype

This attribute allows you to specify which type of script block should be emitted.
 

  • HeadScript: The script block will be inserted in the <head> </head> section of the page. Note: You must be running DNN 3.1.1 or higher for this block type to work.
    (
    New to Version 4.2)
  • ClientScript: The script block will be inserted near the top of the page.
  • ClientScriptInclude: Used for inserting script tags that include a script file. I.e.:
    <script type="text/javascript" src="scripts/myscript.js"></script>
    Use of the block type will place the script block after the page's opening <form> tag and after the DNN script include tags.
    (New to Version 4.5 - Only available on DNN 4.3 and later)
     
  • StartupScript: The script block will be inserted near the bottom of the page.

If no value is specified, the default "ClientScript" will be used.

registeronce

(Optional - default value is False) If this value is True, the tag will first check to see if a code block with scriptid has been registered in the page. If not, it will register your block. If it has been registered already, then no action is taken. If this value is False, then your script block will attempt to register your script block, regardless of any previously registered block.

url

If blocktype is set to ClientScriptInclude, this is the path to the Javascript file you wish to include. It is ignored if blocktype is set to a different value.

 

 

EXAMPLE

<scriptblock scriptid="AlertScripts" registeronce="true">
  <script language="javascript">
    function helloWorld(){
      alert('Hello World');
    }
   function goodbyeWorld(){
      alert('Goodbye Cruel World');
    }
    function showMessage(sMessage){
      alert(sMessage);
    }
  </script>
</scriptblock>
 

Then, elsewhere in your form you can have:

<a href="javascript:void(0)" onclick="helloWorld();">Hello World</a><br />

<a href="javascript:void(0)" onclick="goodbyeWorld();">Goodbye</a><br />

<a href="javascript:void(0)" onclick="showMessage('<xmod:field name="MyMessage"/>')">Show Message</a>