Export (0) Print
Expand All

IHTMLElement2::setExpression method

This element is obsolete and should no longer be used. Sets an expression for the specified object.

Syntax


Integer setExpression(
  [in]            String sPropertyName,
  [in]            String sExpression,
  [in, optional]  String sLanguage = JScript
);

Parameters

sPropertyName [in]

String that specifies the name of the property to which expression is added.

sExpression [in]

String that specifies any valid script(JScript, JavaScript, VBSCript) statement without quotations or semicolons. This string can include references to other properties on the current page. Array references are not allowed on object properties included in this script.

sLanguage [in, optional]

String that specifies one of the following values:

JScript

Default. Language is JScript.

VBScript

Language is VBScript.

JavaScript

Language is JavaScript.

Remarks

Use the setExpression method to add expressions to supported Cascading Style Sheets (CSS) attributes and read/write DHTML Properties. To remove expressions set by setExpression, use the removeExpression method.

The following syntax sections show how to set an expression on DHTML Properties and CSS attributes.

  • Use this syntax to set an expression on a read/write property or on an expando property.
    
    object.setExpression(sPropertyName, sExpression, sLanguage)
    
    
  • Use this syntax to set an expression on a CSS attribute.
    
    object.style.setExpression(sPropertyName, sExpression, sLanguage)
    
    
  • Use the expression() syntax to set an expression on a CSS attribute in HTML.
    
    <element style="sAttributeName:expression(sExpression)">
    
    

The data type of the evaluated expression in the language parameter must match one of the possible values allowed for the expression parameter. If the property or attribute specified by the first parameter requires a string, the data type of the second parameter must be a string. Otherwise, the second parameter is evaluated prior to invoking setExpression, causing the expression to be set to the result of the evaluation.

Use the uniqueID property of an object in an expression to refer back to the object. Using uniqueID is an alternative to specifying an id for expressions that use an object reference.

The cssText property is a unique property that is not compatible with the dynamic properties implementation. Do not use cssText with any dynamic property methods.

The following examples illustrate common problems encountered with the expression parameter in setExpression. The expression appears valid, but may not be.

  • The provided expression is invalid because document.style.fontSize is "npx" and will not add to 13
    
    object.style.setExpression("height","document.style.fontSize + 13"); 
    
    
  • The provided expression is invalid when document.body.style.fontSize is previously unspecified
    
    object.style.setExpression("width","document.body.style.fontSize"); 
    
    

Examples

The following examples use the setExpression method to change the width of a blue box. In each example, the width of the blue box is equal to the sum of the values of the first two text boxes. When a value in one of the text boxes changes, the width of the blue box recalculates.

This example shows the HTML implementation of setExpression.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/recalc_inline.htm


<!DOCTYPE html>
<html>
<head>
  <title>Dynamic Properties Sample</title>
</head>

<body>
  <h1>Inline Dynamic Properties Sample</h1>
  <input type="text" id="box1" value="40" style="width: 40px;"> The sum of the values in these two text boxes determines the width<br>
  <input type="text" id="box2" value="40" style="width: 40px;"> of the blue text box below.<br>
  <input type="text" id="box3" style="background-color: blue; width: 80px;">
  <script>
    var box1 = document.getElementById('box1');
    var box2 = document.getElementById('box2');
    var box3 = document.getElementById('box3');

    box1.addEventListener('change', eventHandler, false)
    box2.addEventListener('change', eventHandler, false)

    function eventHandler(evt) {
      newWidth = parseInt(box1.value) + parseInt(box2.value) + "px";
      if (box3.style.setExpression) {
        box3.style.setExpression('width', newWidth, 'JavaScript');
      }
      else {
        box3.style.setAttribute('width', newWidth);
      }
    }
  </script>
</body>
</html>

See also

IHTMLElement2
IHTMLStyle2
currentStyle
runtimeStyle
style
Reference
getExpression
removeExpression
recalc
Conceptual
About Dynamic Properties

 

 

Show:
© 2014 Microsoft