setExpression Method

DHTML, HTML, & CSS

 
Click to return to the DHTML, HTML & CSS home page    
setEndPoint Method     setInterval Method     DHTML Methods    

setExpression Method


Sets an expression for the specified object.

Syntax

HTML <ELEMENT STYLE="sAttributeName:expression(sExpression)">
Scripting object.setExpression(sPropertyName, sExpression2, sLanguage)

Parameters

sAttributeName Required. String that specifies the name of the attribute to which sExpression is added.
sPropertyName Required. String that specifies the name of the property to which sExpression is added.
sExpression Required. String that specifies any valid Microsoft JScript (compatible with ECMA 262 language specification) 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.
sExpression2 Required. String that specifies any valid script. 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 Required. String that specifies one of the following values:
JScriptLanguage is JScript.
VBScriptLanguage is VBScript.
JavaScriptLanguage is JavaScript.

Return Value

No return value.

Remarks

Use the setExpression method to add expressions to supported cascading style sheets (CSS) attributes and read/write Dynamic HTML (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)

The data type of the evaluated expression in the sExpression parameter must match one of the possible values allowed for the sProperty 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.

Example

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.

Sample Code

This example shows the HTML implementation of setExpression.

<INPUT TYPE=text ID=oBox1 value=40>The sum of the values in 
    these two text boxes determines the width<BR>
<INPUT TYPE=text ID=oBox2 value=40>of the blue text box below.
<BR><INPUT TYPE=text ID=oBox3 
    STYLE="width:expression(eval(oBox1.value) + 
    eval(oBox2.value));background-color:blue">
<BR><INPUT TYPE=button ID=Button 
    value="Click to resize blue box above" 
    onclick="recalc()">

This feature requires Microsoft® Internet Explorer 5 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft 
	 Internet
	 Explorer

This example uses the uniqueID property and the setExpression method to update the innerText property of a table row.

<SCRIPT>
window.onload=fnInit;
function fnInit(){
   var iLen=oSheet.rows.length-1;
   for(var i=1;i<iLen;i++){
      var oRow=oSheet.rows[i];
      var oCells=oRow.cells;
      oCells(3).setExpression("innerText",
         "fnGetValue(" + oRow.uniqueID + ")");
   }
   var oGrand=oSheet.rows(iLen).cells(1);
   oGrand.setExpression("innerText","fnGetTotal()");
}
function fnGetTotal(){
   var iValue=0;
   var iLen=oSheet.rows.length-1;
   for(var i=1;i<iLen;i++){
      iValue+=parseFloat(oSheet.rows(i).cells(3).innerText);
   }
   return iValue;
}
function fnGetValue(oRow){
   var oCells=oRow.cells;
   var oPrice=oCells(2);
   var oQuantity=oCells(1);
   var sPrice;
   var sQuantity;
   if(oPrice.childNodes[0].nodeName=="#text"){
      sPrice=oPrice.innerText;
   }
   else{
      var vPrice=oPrice.childNodes[0].value;
      sPrice=(vPrice==""?"0":vPrice);
   }
   if(oQuantity.childNodes[0].nodeName=="#text"){
      sQuantity=oQuantity.innerText;
   }
   else{
      var vQuantity=oQuantity.childNodes[0].value;
      sQuantity=(vQuantity==""?"0":vQuantity);
   }
   var vAlg1=parseFloat(sPrice) * parseFloat(sQuantity);
   return vAlg1;
}
</SCRIPT>

<TABLE ID="oSheet">
<TR><TH>Product</TH><TH>Quantity</TH>
<TH>Price per #</TH><TH>Totals</TH></TR>
<TR><TD>Browser Putty</TD><TD EDIT="true">2</TD>
<TD EDIT="true">4.99</TD><TD></TD></TR>
<TR><TH COLSPAN=3>Grand Total</TH><TH></TH></TR>
</TABLE>
This feature requires Internet Explorer 5 or later. Click the icon below to install the latest version. Then reload this page to view the sample.
Microsoft 
	 Internet
	 Explorer

Applies To

[ Object Name ]
PlatformVersion
Win16:
Win32:
Mac:
Unix:
WinCE:
Version data is listed when the mouse hovers over a link, or the link has focus.
A, ACRONYM, ADDRESS, APPLET, AREA, B, BDO, BIG, BLOCKQUOTE, BODY, BR, BUTTON, CAPTION, CENTER, CITE, CODE, COL, COLGROUP, custom, DD, DEL, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, Hn, HR, I, IFRAME, IMG, INPUT type=button, INPUT type=checkbox, INPUT type=file, INPUT type=hidden, INPUT type=image, INPUT type=password, INPUT type=radio, INPUT type=reset, INPUT type=submit, INPUT type=text, INS, KBD, LABEL, LEGEND, LI, LISTING, MARQUEE, MENU, NOBR, OBJECT, OL, OPTION, P, PARAM, PRE, Q, RT, RUBY, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, style, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR

See Also

dynamic propertiesInternet Link, getExpression, recalc


Back to topBack to top

Did you find this topic useful? Suggestions for other topics? write us!Internet Link

© 1999 microsoft corporation. all rights reserved. terms of useInternet Link.