How to embed Javascript in form definition

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to embed Javascript in form definition

javaudvikling
Hello Orbeon,

Can you tell me whether it's possible to embed JavaScript code in the form definition, so its automatically embedded in the HTML body section when the form definition is rendered to HTML.  

Form definiton:
..
 <xh:body>
        <fr:view>
            <fr:body>
                     <script type="text/javascript"> function myFunction(){...} </script>                    <noscript>  ...  </noscript>

                        <fr:section id="section-2-control" bind="section-2-bind">
                    <xf:label ref="$form-resources/section-2/label"/>
                    <fr:grid>

After form definition is rendered to html:

<!DOCTYPE HTML>
<html lang="en" id="xf-1">
..
<body class="orbeon xforms-disable-hint-as-tooltip xforms-disable-alert-as-tooltip yui-skin-sam">
...
                    <script type="text/javascript"> function myFunction(){...} </script>                    <noscript> ...  </noscript>
</body>
</html>
Reply | Threaded
Open this post in threaded view
|

Re: How to embed Javascript in form definition

Erik Bruchez
Administrator
With 4.4, there is property to add an external JavaScript file:

http://wiki.orbeon.com/forms/doc/developer-guide/configuration-properties/configuration-properties-form-runner#TOC-Adding-your-own-JavaScript

If you add it within the form definition, you must put it within the `<xh:head>` element, and make sure to use the `xh` prefix for your elements:

    <xh:script type="text/javascript">function myFunction(){...}</xh:script>

-Erik