access global variable from script

How do I access global variable inside a script?

Hi Risala,

Just type the variable name after $ sign.Here is an example:

<button>create window
<e:handler event="click" type="application/xml">
<c:create destination="id('window_area')" mode="appendChild" >
<b:window  >
<c:attribute name="id" select="$myVar"/>
</b:window>
</c:create>
</e:handler>
</button>

global var inside javascript

Hello yudi,
Thanks for the response. My question is related to accessing global variables from inside javascript functions. The above example is showing the access model within XEL. What if the event handler type was text/javascript?

global var inside javascript

Hi risala,

If there is no other word other than the variable name , then you can type it directly otherwise add + to separate between them. For example:

<d:setter type="text/javascript">
alert('Property ' + name + ' is: ' + value);
this._._yourWidget = value;
</d:setter>

You can just use the name of

You can just use the name of the variable directly just as you would access a global javascript variable

<e:variable name="myVar">
        <e:data>
                <root />
        </e:data>
</e:variable>

<div>
        Click me
        <e:handler event="click" type="application/javascript">
                alert(myVar);
        </e:handler>
</div>

When I do this.. the alert show.. Undefined

When I do this.. the alert show.. Undefined

<e:variable name="myVar">
        <e:data type="text/xml">
                Hello!
        </e:data>
</e:variable>

<div>
        Click me
        <e:handler event="click" type="application/javascript">
                alert(myVar);
        </e:handler>
</div>

Xml format

your xml variable are not well defined, "Hello!" isen't a xml document. Test with the following code. I write a valid xml document into "myVar" variable. I use bb.xml serialize to view xml document as string.

<e:variable name="myVar">
        <e:data type="text/xml">
          <root xmlns="">
                <p>Hello!</p>
          </root>
        </e:data>
</e:variable>
<div>
        Click me
        <e:handler event="click" type="application/javascript">
                alert(bb.xml.serialize(myVar));
        </e:handler>
</div>