You are here: Reference > JavaScript > client-side > HTML DOM > methods > getExpression

getExpression method

Browser support:
9
Returns the dynamic expression for the specified DHTML property on the current element.
The support for dynamic properties has been removed in Internet Explorer 9, so none of the getExpression, removeExpression, setExpression and recalc methods are supported. These methods exist in version 8, but using them raises exceptions.
Dynamic expressions (also called dynamic properties) provide a way to specify script expressions for the values of DHTML properties. These expressions are recalculated automatically, but if necessary, they can be explicitly updated with the recalc method. See the example below for details.
Dynamic expressions are also supported for the values of style properties. If you need further information about it, see the pages for the styleObj.getExpression, styleObj.removeExpression and styleObj.setExpression methods.

Syntax:

object.getExpression (propertyName);
You can find the related objects in the Supported by objects section below.

Parameters:

propertyName
Required. String that specifies the name of the DHTML property. This parameter is not case-sensitive. The available property names can be found on the JavaScript pages for the HTML objects.

Return value:

String that retrieves the expression for the given DHTML property. If the given DHTML property is not specified or its value is not an expression, the getExpression method returns undefined.

Example HTML code 1:

This example illustrates the use of dynamic expressions for DHTML properties:
<head>
    <script type="text/javascript">
                // Try..catch blocks need to be used because of Internet Explorer 8
        function GetExp () {
            var input2 = document.getElementById ("input2");
            try {
                var expression = input2.getExpression ("value");
                alert ("Expression is: " + expression);
            }
            catch (e) {
                alert ("Your browser does not support the getExpression method!");
            }
        }
        function SetExp () {
            var input1 = document.getElementById ("input1");
            var input2 = document.getElementById ("input2");
            try {
                input2.setExpression ("value", "input1.value");
            }
            catch (e) {
                alert ("Your browser does not support the setExpression method!");
            }
        }
        function RemoveExp () {
            var input2 = document.getElementById ("input2");
            try {
                input2.removeExpression ("value");
            }
            catch (e) {
                alert ("Your browser does not support the removeExpression method!");
            }
        }
    </script>
</head>
<body onload="SetExp ()">
    When the contents of the first input field are modified, the second input field will be synchronized.
    <input id="input1" />
    <input id="input2" />
    <br /><br /><br />
    With the following buttons, you can get, remove and set the expression that synchronizes the value:<br />
    <button onclick="GetExp ()">Get expression!</button>
    <button onclick="SetExp ()">Set expression!</button>
    <button onclick="RemoveExp ()">Remove expression!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content