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

setExpression method

Browser support:
9
Sets a 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.
To get an expression, use the getExpression method, to remove it, use the removeExpression 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.setExpression (propertyName, expression [, language]);
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.
expression
Required. String that specifies the script expression for the value of the style property.
language
Optional. String that specifies the language of the expression script.
One of the following values:
JavaScript
The language is JavaScript.
JavaScript1.1
The language is JavaScript 1.1.
JavaScript1.2
The language is JavaScript 1.2.
JavaScript1.3
The language is JavaScript 1.3.
JScript
Default. The language is JScript.
VBS
Same as VBScript
VBScript
The language is Microsoft Visual Basic Scripting Edition.

Return value:

This method has no return value.

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